I know that we can attach events with the jQuery on() function and remove them again with off().
In an existing project I do sometimes come
.one('click.namspace') instead of .on('click.namespace').$('p')
.off('click.namespace', clickCB)
.one('click.namespace', clickCB); // note the .one() here
This way you ensure that the click is not called more than once, otherwise, the .on(...) will only keep adding click-event-handlers (clickCBs) to the click.namespace event on p element and will be called multiple times before the .off() is triggered.
Good Luck...
Actually you can attach multiple event handlers to the same event, not just one. Even when namespaces are used. Check out this quick demo.
Actually, one advantage of namespaces is that you can mark a group of event handlers, and easily remove them later to avoid attaching them several times. This is what this line does:
$("#SomeId").off("click.namespace").on("click.namespace");
If there is an existing hander (since you may have more than one, in this case, they will chain), and it calls .stopPropagation(), then your hander will not be called. Writing the code as above will avoid this issue.