jquery Unbind Delete binding events

Source: Internet
Author: User
Tags bind

The Bind method using jquery can bind more than one handler function for an event binding of an object, and can even bind a method multiple times, such as:

The code is as follows Copy Code

$ (XXX). bind (' click ', Fun1). bind (' click ', Fun2). bind (' click ', fun1);

Unbind is used to remove bindings, such as $ (XXX). Unbind (' click ')

......

But what if you just want to delete fun2? See a lot of jquery before the introduction of this operation, so nature has always thought only the whole will click processing, today tried another operation: $ (XXX). Unbind (' click ', fun2) to unbind fun2

Live: $ (XXX). Unbind (' click ', Fun1), will be registered before the two times fun1 all deleted

To delete a binding event

1. Remove binding events for all P elements:

The code is as follows Copy Code

$ ("P"). Unbind ();

2. Remove the Click event for the P element binding:

The code is as follows Copy Code

$ ("P"). Unbind ("click");

$ ("P"). Unbind ("click", Funname);

Note: The Unbind method only applies if you are using document.getElementById ("BTN") directly from the event that the jquery binding is canceled. Onclick=function{//code ...} or <div onclick= "alert (' C ')" >test</div>, cannot be canceled (deleted) by the Unbind method.

Remove Label method

The code is as follows Copy Code

$ ("specified object"). Remove ();=> can be implemented
$ ("#menuTree"). Unbind ()//removing all binding events
$ ("#menuTree"). attr ("Class", "scroll org_tree white");
$ ("#menuTre ul"). Remove ()//delete tree


Add:

Using the $ (selector). Unbind (' hover ') is invalid under jquery, you can use the following method instead:

The code is as follows Copy Code
$ (selector). Unbind (' MouseEnter '). Unbind (' MouseLeave ');
Or:
$ (selector). Unbind (' MouseEnter mouseleave ');

Hover events can be found to be composed of MouseEnter and mouseleave to distinguish between MouseOver and mouseout.
The mouseover and Mouseout events will not be affected after the two events that unbind it.

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.