Access Dynamic DOM elements - Javascript DOM

Javascript examples for DOM:Element appendChild

Description

Access Dynamic DOM elements

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  w ww.  jav  a 2s.  c  om
function addElement() {
    var foo = document.createElement('p');
    foo.id = "bar";
    document.body.appendChild(foo);
}
function getElement() {
    console.log(document.getElementById('bar'));
}
addElement();
getElement();
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials