So, you’ve made a plugin-like block of code that binds many event handlers to certain DOM elements. Later, you want to clean them all up in order to dispose the plugin completely.This could get a little lengthy if you added many handlers. Maybe you don’t even have access to the bound handlers because they belong to another local scope.You can’t unbind every handler for a certain event (or any existing event), because you could be deleting other handlers that you didn’t take into account.
Use a unique name space for each plugin you make. Any handler bound within tippling must be added with this namespace.Later, when cleaning up, you just need to “unbind the whole namespace,” and all the related event handlers will go away with one single line of code.
How to bind with a namespace?
To add a namespace to an event type, you simply add a . followed by the namespace name.
Since jQuery 1.3, you can add more than one (namespace) per event.
This is how you would bind the click and mouse down functions with a namespace:
How to clean up my plugin?
To dispose the bindings above, you would do:
J Query Related Interview Questions
|HTML 4 Interview Questions||HTML Interview Questions|
|HTML 5 Interview Questions||Zend Interview Questions|
|JqueryUI Interview Questions||Dynamic HTML Interview Questions|
|XQuery Interview Questions||jQuery Mobile Interview Questions|
J Query Related Practice Tests
|HTML 4 Practice Tests||HTML Practice Tests|
|HTML 5 Practice Tests||Zend Practice Tests|
|PHP and Jquery Practice Tests||J Query Practice Tests|
|CodeIgniter Practice Tests||Dynamic HTML Practice Tests|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.