Sponsored by Gluten Free Waffles and Sliced Bananas

Friday, March 22, 2013

Event Namespacing with jQuery

2:21 PM Posted by Tyson Nero 2 comments
It's a standard practice to bind and unbind events using general event types such as "click". You would probably do something like this.

However, there are cases, especially with third party libraries for instance, where event collisions could occur. Let's say you bring in a plugin that does some type of magic on a button using click events. You too want to do your own magic and also bind to the click event. Time passes, and for some reason, the plugin gets destroyed and unbinds the click event. Not only has it cleaned up itself, but your event handlers are gone too!

The solution is event namespacing, which is simply adding class names to your events:

Event namespacing comes in extra handy when writing your own plugins. Remember, there are many other plugins out there, and just like writing C# code, you want to define unique namespaces that will hopefully not collide with other libraries.


  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from JQuery Training in Chennai . or learn thru JQuery Training . or learn thru ES6 Online Training. Nowadays JavaScript has tons of job opportunities on various vertical industry.

  2. This is an awesome post. Really very informative and creative contents. This concept is a good way to enhance knowledge. I like it and help me to development very well. Thank you for this brief explanation and very nice information. Well, got good knowledge.
    WordPress development company in Chennai