Created
July 11, 2016 19:24
-
-
Save vinicius-stutz/2e1dd6d7c1a8fbc3462b59396b6a7e10 to your computer and use it in GitHub Desktop.
Remove jQuery Plugin Instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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