html - div not firing onclick event in javascript -
my div element :
<div id="div"></div>
below javascript.:
function makediv() { var divmy = document.getelementbyid("div"); var row =''; var color='#ccc'; for(var i=0;i<2;i++) { divmy.innerhtml += " <div class='dynamic' id='inner"+i+"' onclick=searchfilterations(i)>"+i+"</div> "; color='black'; } } function searchfilterations(e){ alert(e); }
problem is: searchfilterations() function not firing on click.what error? here fiddle : http://jsfiddle.net/cjt4s/4/
please call makediv
function onload
event
window.onload = makediv; function makediv() { var divmy = document.getelementbyid("div"); var row =''; var color='#ccc'; for(var i=0;i<2;i++) { // divmy.innerhtml += " <div style='width: 100px;height: 30px;background-color:"+color+" ;' onclick=javascript:alert("+i+")></div> "; divmy.innerhtml += " <div class='dynamic' id='inner"+i+"' onclick=searchfilteration("+i+")>"+i+"</div> "; color='black'; } } function searchfilteration(i){ alert(i); }
Comments
Post a Comment