Processing hover events using jQuery's live () method

Source: Internet
Author: User

Hover ([over,] out)

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.

$ ('. 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.

$ ('. 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 ......

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.