Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 597
Abs Avatar asked May 20 '10 21:05

Abs


1 Answers

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/

like image 196
karim79 Avatar answered Sep 22 '22 03:09

karim79