Example of how jQuery's live () method processes hover events _ jquery

Source: Internet
Author: User
A method that imitates the hover event. When you move the cursor over a matched element, the specified first function hover ([over,] out) is triggered)

A method that imitates a hover event (move the mouse over an object and remove it)

When you move the cursor over a matching element, the specified first function is triggered.

When you move the cursor out of this element, the specified second function is triggered.

The Code is as follows:


$ ('. MyDiv'). hover (function (){
DoSomething...
}, Function (){
DoSomething...
});


The problem is that some elements, such as menus, are dynamically loaded using AJAX.

The menu has not been loaded yet, so we need to use another jquery method live ()

The. live () method is valid for an element that has not been added to the DOM because event delegation is used:

Event Handlers bound to the ancestor element can respond to events triggered on future generations.

The event handler function passed to. live () is not bound to an element,

Instead, it serves as a special event handler and binds it to the root node of the DOM tree.

The Code is as follows:


$ ('. MyDiv'). live ('hover ', function (event ){
If (event. type = 'mouseenter '){
DoSomething...
} Else {
DoSomething...
}
})


Some jquery versions respond to mouseenter and mouseleave
Some are mouseover and mouseout.
Waiting for research ......
Related Article

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.