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
Post a Comment