I have a piece of code that needs an element. The element is dynamicly loaded so I need to check if it has been loaded so I can execute my script. How could I do this? This has not been giving me errors before, but now it is... strange Javascript Code: echeck = document.getElementById('etobechecked'); if(echeck != null) { //code here } Code (markup):
Hi, I have also used a similar method, it works fine for me.. Here is the code, you may give it a try, function loadelement() //to append an element to a form tag with id="F1" { var el = document.createElement("input"); el.setAttribute("id","dynelement"); el.setAttribute("type","button"); el.setAttribute("value", "hi"); el.setAttribute("onclick","test()"); f1.appendChild(el); } function checkelement() //to check for the presence of this element. { if(document.getElementById("dynelement")!=null){ alert("loaded");} else{ alert("not yet loaded");} } ------------ the following is the html part for this ------- <input type="button" id="b1" onclick="loadelement()" value="addelement" /> <input type="button" id="check" onclick="checkelement()" value="Check for Element" /> Code (markup): I am dubious that you may have invoked the checking script prior to appeding script. regards d_s.