Dom Manipulation - altering the DOM, create div element, add class and set text content - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Dom Manipulation - altering the DOM, create div element, add class and set text content

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
    document.addEventListener('DOMContentLoaded', function() {
        const container = document.querySelector('#container');
        const content = document.createElement('div');
        content.classList.add('content');
        content.textContent = 'Dom text-content!';
        container.appendChild(content);//from  ww  w . j  a  va2 s  .  c om
    }, false);
    
      </script> 
      <h1> test test test</h1> 
      <div id="container"></div>  
   </body>
</html>

Related Tutorials