Checking if jQuery .hover action is already binded

2019-08-09 07:18发布

问题:

This question already has an answer here:

  • Check if event exists on element [duplicate] 9 answers

Is there any way to check if an element already has an action, triggered by jQuery .hover function?

回答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'];


回答2:

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);});
});