jquery die () usage

Source: Internet
Author: User

Die ()
If you know. Bind (), then you must know. Unbind (). So,. Die () and. Live () are similar relationships. To get in touch with the above bindings (the pop-up dialog box does not want the user to click on the link), we do this:
Copy code code as follows: $ (' a '). Die ();

More specifically, if there are other events that are bound and need to be preserved, such as hover or others, you can only unbind the click event.
Copy code code as follows: $ (' a '). Die (' click ');

More specifically, if you have already defined a method name, you can unbind the specified method.
Copy code code as follows:
Specialalert = function () {
Alert ("You are now leaving this site");
return true;
}
$ (document). Ready (function () {
$ (' a '). Live (' click ', Specialalert);
$ (' a '). Live (' click ', someotherfunction);
});
Then somewhere else, we could unbind only the the
$ (' a '). Die (' click ', Specialalert);

On the question of. Die ()
When using these functions, the. Die () method has a disadvantage. You can use only the element selectors that are used in the. Live () method, for example, you cannot write as follows:
Copy code code as follows:
$ (document). Ready (function () {
$ (' a '). Live (' click ', function () {
Alert ("You are now leaving this site");
return true;
});
});
It would be nice if we could then choose specific elements
To unbind, but this'll do nothing
$ (' A.no-alert '). Die ();

The. Die () event appears to match the target selection and unbind the. Live (), but in fact, there is no binding for $ (' A.no-alert '), so jquery cannot find any bindings to remove, and it won't work.
What's worse is the following:
Copy code code as follows:
$ (document). Ready (function () {
$ (' A,form '). Live (' click ', function () {
Alert ("You are going to a different page");
return true;
});
});
Neither of these would work
$ (' a '). Die ();
$ (' form '). Die ();
Only this would work
$ (' A,form '). Die ();

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.