jquery uses the Unbind method to remove hover events and other methods introduced

Source: Internet
Author: User

Recently, project development is very busy, one of the requirements is to achieve responsive navigation. (Response-style questions we communicate in CSS-related blogs)

Everyone knows that navigation needs to be down to the menu effect, and will inevitably use the hover () method of jquery. If the navigation is on the ipad, the natural hover () is meaningless. How do I cancel the hover () and add the touch event?

Today, jquery needs to remove the hover of the problem, the original thought of direct unbind ("hover") can be done, but the half-day error.

The reason is really simple, hover is not an event. Open the reference manual, hover is actually composed of MouseEnter and MouseLeave. This is a very clear question!

/*this method is wrong.*/$ (#hover_div). Unbind ("Hover");/*This method is also wrong.*/$ (#hover_div). Unbind ("mouseover"). Unbind ("Mouseout");/*This method is new and cannot be used in the old version .*/$ (#hover_div). Unbind ("MouseEnter MouseLeave");/*This method is correct, both the old and new versions are available*/$ (#hover_div). Unbind ("MouseEnter"). Unbind ("MouseLeave");

The code above suggests the use of a fourth, relatively safe. (I did not test the specific version to support the third method) if you feel uncomfortable, you just download the new version of jquery, use the Third Kind!

Anyway, the problem is solved, then write the code! Industrious yards of farming.

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.