Javascript examples for DOM:Element appendChild
Access Dynamic DOM elements
<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>