Javascript DOM How to - Show dynamically created a div








Question

We would like to know how to show dynamically created a div.

Answer


<!DOCTYPE html>
<html>
<body>
  <p>Here's some example text</p>
  <script type='text/javascript'>
        var jselem = document.createElement ("div");
        jselem.innerHTML = '<p>and new content \'</p>';
        document.body.appendChild(jselem);
    </script>
</body><!--from  ww  w .  j  a va2  s. co  m-->
</html>

The code above is rendered as follows: