Reputation: 21834
This works ( .hover
):
$('a.directory:not(.trashContent), a.file:not(.trashContent)').hover(function() {
if (!dragged) $(this).find('a.suppr:first').show();
}, function() {
$(this).find('a.suppr:first').hide();
});
And this does not work ( .live('hover')
):
$('a.directory:not(.trashContent), a.file:not(.trashContent)').live('hover', function() {
if (!dragged) $(this).find('a.suppr:first').show();
}, function() {
$(this).find('a.suppr:first').hide();
});
Any idea why?
Upvotes: 0
Views: 129
Reputation: 5681
The reason why it doesn't work is, that hover is not really a single event. It binds together the event handlers for mouseenter and mouseleave. Means hover itself is not really an own event handler. To make it work with live (better use .on() ) you must use the event handlers seperated.
$("#Element").live({
mouseenter:function(){
//do something
},
mouseleave:function(){
//do something
}
});
Upvotes: 3
Reputation: 41934
.live is old. Since jQuery 1.7 there is a total new Event API in jQuery and you should use .on()
for all events.
An example:
$('a.directory:not(.trashContent), a.file:not(.trashContent)').on('mouseenter', function() {
console.log('You have hovered on ' + $(this));
});
And you can better select elements combinated with .is()
:
$('a.directory, a.file').is(':not(.trashContent)', function() {
var $elem = jQuery(this);
$elem.on('mouseenter', function() {
console.log('You have hovered on ' + $elem);
});
});
Upvotes: -2