Rate this script:  I Love it  /   I Hate it

Add an element with the DOM


Code



        function runIt(){
// create a DIV element, using the variable eDIV as a reference to it
eDIV = document.createElement("div");
//use the setAttribute method to assign it an id
eDIV.setAttribute("id","myDiv");
// add the text "hello world" to the div with createTextNode
eDIV.appendChild(document.createTextNode("hello world"));
// append your newly created DIV element to an already existing element.
document.getElementById("mContainer").appendChild(eDIV);
        }
 

 

 
Add an element with the DOM scripts | Add an element with the DOM snippet | Add an element with the DOM example | Add an element with the DOM tutorial | Add an element with the DOM code