You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In jQuery, when you bind use click() or focus(), you bind to the general purpose event. However, if you use the bind() function, you can specify a namespace for the event, such as bind('click.chosen'). This event will still be triggered by regular click events or even specific ones (like trigger('click.chosen') without triggering other namespaced events).
The purpose of doing this is so that when you UNBIND, you do not unbind everyone else's callbacks. Most of the time this isn't a big deal, but if the app dev or a third party wants to bind events to the same elements as you, or if you bind onto global events (such as $(document).click(), which IS done for hiding) then when you go and UNBIND the general click events you will be unbinding everyone elses callbacks. Instead, pass the namespace to unbind and you will prevent breaking anyone else's code.
This should be a mandatory standard for all jQuery plugins, but unfortunately I think few people actually know about it. It's causing issues for me in some of my code and most of the event binds are abstracted and hard to find for me to refactor.
The text was updated successfully, but these errors were encountered:
In jQuery, when you bind use
click()
orfocus()
, you bind to the general purpose event. However, if you use thebind()
function, you can specify a namespace for the event, such asbind('click.chosen')
. This event will still be triggered by regularclick
events or even specific ones (like trigger('click.chosen') without triggering other namespaced events).The purpose of doing this is so that when you UNBIND, you do not unbind everyone else's callbacks. Most of the time this isn't a big deal, but if the app dev or a third party wants to bind events to the same elements as you, or if you bind onto global events (such as $(document).click(), which IS done for hiding) then when you go and UNBIND the general click events you will be unbinding everyone elses callbacks. Instead, pass the namespace to unbind and you will prevent breaking anyone else's code.
This should be a mandatory standard for all jQuery plugins, but unfortunately I think few people actually know about it. It's causing issues for me in some of my code and most of the event binds are abstracted and hard to find for me to refactor.
The text was updated successfully, but these errors were encountered: