0

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?

GG.
  • 21,083
  • 14
  • 84
  • 130

2 Answers2

3

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
  }
});
Sven Bieder
  • 5,515
  • 2
  • 21
  • 27
  • the `live` method is deprecated, if using jquery version 1.7+ use `on` or else use `delegate` – Rafay Jan 20 '12 at 14:11
-2

.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);
  });
});
Wouter J
  • 41,455
  • 15
  • 107
  • 112