简体   繁体   中英

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 JQuery? 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM