Is there any way to check if an element already has an action, triggered by jQuery .hover function?
Asked
Active
Viewed 667 times
1
-
2There is no documented way to do it that doesn't use internal methods that are subject to change from version to version. – Kevin B Mar 25 '13 at 14:17
-
There's no easy way to do that, but you can check `$._data( elem, "events" );` and see if mouseenter/leave has been bound. – adeneo Mar 25 '13 at 14:17
-
check this http://stackoverflow.com/questions/1236067/test-if-event-handler-is-bound-to-an-element-in-jquery – ebram khalil Mar 25 '13 at 14:19
2 Answers
1
You can check it by checking element.data('events')['eventName']
In case of hover, it will be:
var hasHover = x.data('events')['mouseover'] && x.data('events')['mouseout'];
In jQuery 1.8 and later, you must access it using $._data
as mentioned in this answer
i.e.
var events = $._data(obj[0], "events");
var hasHover = events['mouseover'] && events['mouseout'];

Community
- 1
- 1

techfoobar
- 65,616
- 14
- 114
- 135
-
2
-
@KevinB - Ahh, didn't know that detail. Been using the above technique for a couple years now. But yes, I been using versions <= 1.7.2 – techfoobar Mar 25 '13 at 14:20
-
-
It's still using undocumented methods that shouldn't be used for much more than debugging. – Kevin B Mar 25 '13 at 14:24
0
have a look at the filter on the selector
$('.result').each(function(){
$(this).hover(function() {
$(this).filter(':not(:animated)').animate({
'height':'110px',
},160);
},function(){$(this).animate({'height':'38px'},80);});
});

john Smith
- 17,409
- 11
- 76
- 117