开发者

jquery remove plugin from element

I've got something similar to the following code:

$(a).click(function() {
  $(element).plugin();
});

Is there a way to remove a plugin from an element other than using $($.plugin).remove()? Not sure if I h开发者_如何学Cave the terminology correct but basically I want to reset the element to it's original state.

Thanks


Here is my dirty solution:

$('#myWidget,#myWidget *').unbind().removeData();


You'd have to know what the plugin does in order to reverse it's effects. Many plugins add extra elements to the DOM, handlers to elements, etc. If the plugin doesn't create any extra elements, you might be able to simply do a clone (without data and events) and replace or even just unbind all event handlers, but that's not always going to be effective. It would be very dependent on the plugin in question.


Unless the plugin provides that functionality, it probably can not be done that easily. You'll have to investigate what the plugin does, and specifically undo those things - or store a clone of the non-plugged-in element to replace it with later.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜