views:

48

answers:

3

Is there a way to "unbind" a jQuery plugin from a jquery selector?

+1  A: 

Generally no.

The plugin typically makes changes to the elements that you apply it to. Sometimes those can simply be undone by removing the attributes or unbinding the events that the plugin added, but the plugin would need to provide this functionality, or you would have to know exactly what to remove.

Sometimes plugins overwrite information so that you can't undo it without knowing what the information was before the plugin was applied.

Guffa
+2  A: 

You can unbind the plugin name from the jQuery prototype object with delete:

delete $.fn.pluginName;

This doesn't affect already initialized plugin instances though.

reko_t
so how can we unbind the plugin after initialization?
fuSi0N
Plugins usually provide a method of destroying themselves, eg. if you look at jQuery UI, they provide the 'destroy' method, so you can do eg: `$('selector').sortable('destroy');` But there is no uniform way to do this, as the plugin has to run specific piece of code to clean up after itself, and jQuery can't do that for you.
reko_t
A: 

ASAP,

$.myPlugin = null;
Topera