Hover ([Over,]out)
A method that mimics a hover event (the mouse moves over an object and removes it)
When the mouse is moved above a matching element, the first specified function is triggered.
When the mouse moves out of this element, the specified second function is triggered.
Copy Code code as follows:
$ ('. Mydiv '). Hover (function () {
DoSomething ...
}, function () {
DoSomething ...
});
The problem is that some elements, such as menus, are dynamically loaded via Ajax, and the hover method executes
The menu hasn't been loaded yet, so another way to use jquery is Live ()
The live () method is valid for an element that has not yet been added to the DOM because of the use of an event delegate:
Event handlers that are bound to ancestor elements can respond to events that are triggered on a descendant.
Event handlers passed to. Live () are not bound to the element.
Instead, he acts as a special event handler, bound to the root node of the DOM tree.
Copy Code code as follows:
$ ('. Mydiv '). Live (' hover ', function (event) {
if (event.type== ' MouseEnter ') {
DoSomething ...
}else{
DoSomething ...
}
})
Some jquery versions respond to MouseEnter and MouseLeave.
Some mouseover and mouseout.
To be verified ...