jquery's Live () method for handling hover events sample _jquery

Source: Internet
Author: User
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 ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.