Created
September 1, 2015 09:20
-
-
Save scabbiaza/ecab1f18f5c168d3e9b5 to your computer and use it in GitHub Desktop.
Bind/unbind with namespaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // handler for click event | |
| var h1 = $("h6").bind("click", function () { | |
| console.log('click handler'); | |
| }); | |
| // handler for click event with namespace | |
| var h2 = $("h6").bind("click.namespace", function () { | |
| console.log('click handler with namespace'); | |
| }); | |
| // click event result: | |
| // > click handler | |
| // > click handler with namespace | |
| // next click event result: | |
| // > click handler | |
| // > click handler with namespace | |
| //------------------------------------------------------------------------------ | |
| // handler for click event | |
| var h1 = $("h6").bind("click", function () { | |
| console.log('click handler'); | |
| }); | |
| // handler for click event with namespace and unbind by this namespace | |
| var h2 = $("h6").bind("click.namespace", function () { | |
| console.log('click handler with namespace'); | |
| $("h6").unbind("click.namespace"); | |
| }); | |
| // click event result: | |
| // > click handler | |
| // > click handler with namespace | |
| // next click event result: | |
| // > click handler | |
| //------------------------------------------------------------------------------ | |
| // handler for click event and unbind click event | |
| var h1 = $("h6").bind("click", function () { | |
| console.log('click handler'); | |
| $("h6").unbind("click"); | |
| }); | |
| // handler for click event with namespace | |
| var h2 = $("h6").bind("click.namespace", function () { | |
| console.log('click handler with namespace'); | |
| }); | |
| // click event result: | |
| // > click handler | |
| // > click handler with namespace | |
| // next click event result: | |
| // > [nothing here] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment