hover([over,]out)
A simulated hover event (the mouse moves to a ObjectMethods on and out of this object
When the mouse moves over a matching element, the specified first function will be triggered .
When the mouse moves out of this element, the specified second function will be triggered.
$('.myp').hover(function() { doSomething... }, function() { doSomething... });
The problem is that some elements such as menus are dynamically loaded through AJAX. When the hover method is executed,
the menu has not yet been loaded. It is loaded, so we need to use another method of jquery, live()
.live() method can be effective for an element that has not been added to the DOM because it is used Event delegate:
Event handlingFunctions bound to ancestor elements can respond to events triggered on descendants.
The event handler passed to .live() will not be bound to the element,
but will be treated as a special The event handling function is bound to the root node of the DOM tree.
$('.myp').live('hover',function(event){ if(event.type=='mouseenter'){ doSomething... }else{ doSomething... } })
Requires jQuery 1.4.3+
Because hover is not a standard event, it cannot be processed directly using live, so the following method is used instead, with the same effect.
$("table tr").live({ mouseenter: function() { //todo }, mouseleave: function() { //todo } });
The above is the detailed content of Detailed explanation of how the live() method handles hover events in jQuery. For more information, please follow other related articles on the PHP Chinese website!