Example of the live () method of jquery for handling hover events

Source: Internet
Author: User

A method that mimics a hover event that triggers the specified first function when the mouse moves over a matching element

Hover ([Over,]out) a method that mimics a hover event (the mouse moves over an object and moves it out) when the mouse moves to a matching element, the specified first 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 like menus are dynamically loaded through Ajax, when the hover method executes, the menu is not loaded yet, so another way to use jquery is Live (). The live () method works 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.  The event handler function passed to. Live () is not bound to the element, but rather as a special event handler, bound 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 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.