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 ();