Given this:
HTML
<button id="btn">Click me</button>
<br/>
<div id="result"></div>
JS
$("#btn").on("click.mynamespace", function (e) {
$("#result").text("namespace: " + e.namespace);
});
Why is namespace always undefined?
EDit:
What I want to be able to do is connect multiple instances of an event handler to a button's click event. Then, when the button is clicked, each instance is called, in turn. Each instance of the event handler then needs to disconnect itself, so that if the button is clicked again, that handler instance is not called.
The namespace
property is only defined if the event was triggered using jQuery's .trigger
or .triggerHandler
methods. Otherwise, how would jQuery know which namespace to use if there were multiple?
http://jsfiddle.net/GYyef/2/
http://api.jquery.com/event.namespace/
If your goal is to have the event only happen once, the .one()
method would be more appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With