javascript - Click event not executed -
an onmouseover on cell generates div inside cell. div has onclick. onclick not executed. here's sample code: jsfiddle
javascript:
var oldcell=''; function adddiv(cell){ if(oldcell != ''){ oldcell.innerhtml = ''; } cell.innerhtml = "<div class='innerdiv' onclick='console.log(this.parentnode);'></div>"; oldcell = cell; } html
<table border='1px solid black'> <tr> <td class='cell' onmouseover='adddiv(this)'></td> <td class='cell' onmouseover='adddiv(this)'></td> </tr> <tr> <td class='cell' onmouseover='adddiv(this)'></td> <td class='cell' onmouseover='adddiv(this)'></td> </tr> </table> i've tried focussing on div, not wok either. i've tried giving cell onclick, , focussing on cell instead of div, doesn't work in chrome, in ff though.
it appears mouseover event creating new object inside of everytime "mouseover" event called. clicking on object fires mouseover event, replacing element , therefore making impossible call onclick event.
my guess @ event list: - mouseover - mousedown -> mouseover - object replaced. - mouseup (doesn't count click, because new object receiving mouse up)
edit:
if goal create mousehover effect should use css's hover keyword.
see fiddle trying do: http://jsfiddle.net/tb2kk/27/
edit: similar how you're doing it, need check if div exists. 1 way assign id: http://jsfiddle.net/mzdpn/
Comments
Post a Comment