Take the 2-minute tour ×

Given this:


<button id="btn">Click me</button>
<div id="result"></div>


$("#btn").on("click.mynamespace", function (e) {
    $("#result").text("namespace: " + e.namespace);

Why is namespace always undefined?


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.

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

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?



If your goal is to have the event only happen once, the .one() method would be more appropriate.

share|improve this answer
oh, i'd hoped that all handlers would be called for the click event, and in each handler i would be able to retrieve the namespace in order to disconnect the event handler. –  slippyr4 Mar 26 '13 at 19:43
@slippyr4 the event data mentioned by karim79 would be the way to do that, however, if you only want the event to happen once, the .one method would be more appropriate. –  Kevin B Mar 26 '13 at 19:44
post that as an answer, it's exactly what i wanted! –  slippyr4 Mar 26 '13 at 19:55
add comment

Your Answer


