Set text content with element.textContent attribute - Javascript DOM

Javascript examples for DOM:Element textContent

Description

Set text content with element.textContent attribute

Demo Code

ResultView the demo in separate window

<html>
   <body> 
      <h1> Travel Worthy </h1> 
      <div id="message">
         Welcome to our site!/*  w w  w  .  j  ava2s  .  com*/
      </div> 
      <img src="http://www.java2s.com/style/download.png">  
      <script type="text/javascript">
      var msg = 'this is a test!';
      function updateMessage() {
         var el = document.getElementById('message');
         el.textContent = msg;
      }
      updateMessage();
  
      </script> 
   </body>
</html>

Related Tutorials