Use document.getElementById().innerHTML to rewrite the original html - Javascript DOM

Javascript examples for DOM:Document getElementById

Description

Use document.getElementById().innerHTML to rewrite the original html

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from www  . j ava2s  .c om
var myElement = document.getElementById('test');
var originalText = myElement.innerHTML.toString();
myElement.innerHTML = originalText+" new text";
    }

      </script> 
   </head> 
   <body> 
      <div id="test">
         original text
      </div>  
   </body>
</html>

Related Tutorials