My contemplations and diurnal novelties are publicized here


How you apply and remove event handlers may also cause problems that can be really hard to troubleshoot. E.g if you had attached a function to the window.resize event. Calling the following script will remove all window.resize handlers:

$(window).unbind(‘resize’);

jQuery provides an easy way to avoid this: Namespaced Events. When binding a function to an event, simply add a namespace:

$(window).bind(‘resize.mynamespace’, function () {

// Do something useful

});

Now if you need to unbind the function from the event, you can do it safely without affecting other scripts that use the same event:

$(window).unbind(‘resize.mynamespace ‘);

References:-

http://www.456bereastreet.com/archive/201205/safer_event_handling_with_jquery_namespaced_events/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: