jQuery unbind from event handler

Published on 2024-06-24 by Raul

Whenever I used jQuery for client side code, I created a separate function for the event handler, so I could detach it later. But now, I discovered event namespace, which helps prevent unnecessary declarations; it will allow you to specify a namespace whenever attaching to an event, and will also allow you to remove all handlers for that namespaces.

So, you can write code like

$("a.button").on("click.myButtonNamespace", function() {
	//do stuff here

Have a look at the jQuery docs for event namespaces.

Keep in touch


Hey there, I'm Raul, owner of CreativeCLR, a small consulting company.

Feel free to drop me any question you might have on this post using the comment section or the contact page.