When you create an element you must append it to something inside the HTML document to give it scope (visibility). // this code does NOT work
newdiv = document.createElement("div"); // set div attributes newdiv.className = "x"; newdiv.id = "mine"; ... mydiv = document.getElementById("mine"); // does not find it
////////////////////////////
//this code DOES work
newdiv = document.createElement("div"); // set div attributes newdiv.className = "x"; newdiv.id = "mine";
document.body.appendChild(newdiv); // or some other node ... mydiv = document.getElementById("mine"); // finds it
http://www.zytrax.com/tech/dom/createelement.html)
newdiv = document.createElement("div"); // set div attributes newdiv.className = "x"; newdiv.id = "mine"; ... mydiv = document.getElementById("mine"); // does not find it
////////////////////////////
//this code DOES work
newdiv = document.createElement("div"); // set div attributes newdiv.className = "x"; newdiv.id = "mine";
document.body.appendChild(newdiv); // or some other node ... mydiv = document.getElementById("mine"); // finds it
http://www.zytrax.com/tech/dom/createelement.html)