appendChild of objects containing javascript attributes -


i have javascript function

function webit(thumb){     webi = document.createelement("img");     webi.alt=thumb.id.replace("t", "");     webi.id = "w"+webi.alt;     webi.classname = "web";     webi.src= thumb.src.replace("thm","web");     webi.height=233;     webi.onclick='alert()';     document.body.appendchild(webi); } 

which supposed embed larger version of thumbnail image end of document. works fine except javascript function ( ie onxxx) stays resolutely null. seems no matter js function use , afaict thing try set to.

the above example uses

    webi.onclick='alert()'; 

which fails leaving onclick null, though other statements succeed.

when in javascript .onclick property expects function not string

webi.onclick=function(){ alert(); }; 

you use addeventlistener method set event handler

webi.addeventlistener("click",function(){ alert(); }); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -