Skip to content

Instantly share code, notes, and snippets.

@vinicius-stutz
Created July 11, 2016 19:24
Show Gist options
  • Save vinicius-stutz/2e1dd6d7c1a8fbc3462b59396b6a7e10 to your computer and use it in GitHub Desktop.
Save vinicius-stutz/2e1dd6d7c1a8fbc3462b59396b6a7e10 to your computer and use it in GitHub Desktop.
Remove jQuery Plugin Instances
var $element = $('div#test');
// You can examine all of the events attached to an element
$._data($element.get(0), 'events');
// Remove namespaced events added using .on()
$element.off('pluginNamespace');
// Remove namespaced events added using .bind()
$element.unbind('.pluginNamespace');
// Here’s all wrapped up in a handy function
function($elem, eventNamespace) {
var isInstantiated = !! $.data($elem.get(0));
if (isInstantiated) {
$.removeData($elem.get(0));
$elem.off(eventNamespace);
$elem.unbind('.' + eventNamespace);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment