Events bound to live and unbound from jQuery

Source: Internet
Author: User

This article will introduce the live binding events and unbinding methods in jQuery. I hope this article will be helpful to you.

One $. fn. live repeat binding

Solution:

Use the die () method to unbind all events bound to the element before binding the live () method, and then bind new events using the live () method.

 

The Code is as follows: Copy code
// Unbind from the die () method and then use live () Binding
$ ("# SelectAll"). die (). live ("click", function (){
// Event Running code
});


2. Events that unbind live

Solution: Use the unbind ("click") method to unbind the Bound event and then bind the new event. That is, remove the original event on the object before binding the event to the object.

The Code is as follows: Copy code

Var accoutEdit = function (){
$ (This). text ("Unbind event ");
// Unbind live
$ ('. SetAccoutEdit. option'). die ('click', accoutEdit );
}

// Bind the modification event
$ ('. SetAccoutEdit'). live ('click', accoutEdit );

/* Disable the function */
$ ('. EditOption'). live ('click', function (){

$ (This). text ("add binding event ");
// Add accoutEdit binding
$ ('. SetAccoutEdit. option'). live ('click', accoutEdit );

});

In addition
Bind events, unbind events
Events bound with delegate are unbound from undelegate.
Use the on binding event, and use off to unbind

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.