jquery uses namespaces to remove binding events _jquery

Source: Internet
Author: User

This article illustrates how jquery uses namespaces to remove binding events. Share to everyone for your reference. The specific analysis is as follows:

A recent study of jquery found a simple way to remove binding events, namespaces.

The example is simple.

Here I've bound three events, the Click,mouseover and DblClick events, respectively.
Where the click and MouseOver events I joined the namespace, and DblClick did not join the namespace.
A button is used to remove the bound event.
This avoids the repeated use of the bind and Unbind methods to make your code look simpler and clearer.

Copy Code code as follows:
<script type= "Text/javascript" src= "Js/jquery-1.3.2.js" ></script>
<script type= "Text/javascript" >
$ (function () {
$ ("div"). Bind ("Click.plugin", function () {

$ ("Body"). Append ("<p>click event </p>");
});
$ ("div"). Bind ("Mouseover.plugin", function () {

$ ("Body"). Append ("<p>mouseover event </p>");
});
$ ("div"). Bind ("DblClick", function () {

$ ("Body"). Append ("<p>dblclick event </p>");
});
$ ("#but"). Click (function () {
Alert ("Remove");
$ ("div"). Unbind (". Plugin");
});
})
</script>

<div style= "border:1px solid red;height:100px;width:300px;" > has already bound the layer </div> of the <br/>click,mouseover,dblclick event
<input id= "But" type= "button" value= "Remove" ></input>

The operation effect is as follows:

I hope this article will help you with your jquery programming.

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.