Why is event.namespace undefined for a click event?
Considering 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 the namespace always undefined?
EDIT:
What I want to do is connect multiple instances of the event handler to the button click event. Then, when the button is pressed, each instance is called in turn. Each instance of the event handler must be disabled, so if the button is pressed again, this instance of the handler is not called.
+6
1 answer
The namespace
property is defined only if the event was fired using the jQuery .trigger
or .triggerHandler
. Otherwise, how does jQuery know which namespace to use if there were several?
http://api.jquery.com/event.namespace/
If your goal is for the event to happen only once, the .one()
method would be more appropriate.
+8