JavaScript

How to Append or Add text to a DIV using JavaScript

In this tutorial, we are going to see how to append or add text to a DIV element using the innerHTML property of the <div> element in JavaScript. The innerHTML property defines or returns the HTML content of an element.
 

Script to append or add text to a DIV using JavaScript
<html>
   <body>
      <div id="myDiv">Welcom to </div>
   </body>
   <script type="text/javascript">
      var div = document.getElementById('myDiv');
      div.innerHTML += 'StackHowTo!';
   </script>
</html>

Output:

Welcom to StackHowTo!
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *