javascript - How to access newly created elements by pure js? -
i made 'warning' layer use instead of 'alert()'.
code : warning = document.getelementbyid('warning'); // line want make functional. code out side of warning(); line runs before 'elem:div#warning' made warning(). function warning() { = document.createelement('div'); document.body.appendchild(a); a.id = 'warning'; a.classname= 'warning'; }
but don't know how access newly created , added element javascript.
i think css works fine newly added elements. js not.
i searched google, , found methods register newly created element automatically using prototype, hard understand me...
so, trying is, access newly created element 'a' javascript executed before 'a' created.
i tried method :
if(document.getelementbyid('warning')) {alert('asdf')};
but useless...
try fiddle, works me, did small change.
function warning() { = document.createelement('div'); document.body.appendchild(a); a.id = 'warning'; a.classname= 'warning'; } warning(); warningdiv = document.getelementbyid('warning'); if(document.getelementbyid('warning')) { alert('warning div on dom') };
Comments
Post a Comment