Unbind Events with JQuery: Does it work with events setup in HTML?
I have a few onclick and on mouseover events in my html generated by PHP, something like this:
<div onmouseover="fave('heart_<?php echo $row['id']; ?>';" class="heart"><a href=""></a></div>
I wish to make use of unbind on the mouseover but it hasn't worked when I tried this:
$('#'+ id).unbind('mouseover');
So I am guessing unbind will only work with events created by JQu开发者_StackOverflow社区ery? Is there something else I can try?
Btw, I can't move my events to a separate js file as each id is unique.
Thanks all
No, it does not. unbind
will not remove events registered through the inline model. Any event registration model events you create (bound to the same element) will overwrite your inline code, but still, unbind
will leave those intact. In other words, yes, unbind will only unbind event handlers bound to the element using jQuery.
See for yourself: http://jsfiddle.net/ktLTL/
精彩评论