So far, we've seen how we can delegate events and create handlers that can take custom triggers. These methods are perfect if we have a single click event handler, but what happens if we need to have multiple click handlers, for example?
Well, fortunately there's a simple solution: add a namespace to the event! Rather than talk about how it works, let's take a quick look at the following example:
$("#element") .on("click", doSomething) .on("click", doSomethingElse);
This code is perfectly acceptable – nothing wrong with this at all. Sure, it might not be quite as readable as some might like, but we're not worried about that – at least not for now!
The critical point here is if we were to call:
$("#element").off("click");
Then we would lose not only the first click handler, but the second one as well. This is not ideal. We can fix this by adding a namespace or identifier to the command, as shown next:
$("#element") .on("click.firsthandler", doSomething) .on("click.secondhandler...