Search code examples
jqueryjquery-uijquery-widgets

Call destroy of unknown jQuery widget


We are writing a framework and are kind of stuck on a situation. Whenever a widget (all these widgets are custom developed with us and source code is available) is applied we update out widgetCollection, and later it is required to destroy all the widgets registered with our widgetCollection.

Here comes out problem: suppose widget widget-name is applied on DOM #domElementID I can call destroy like

eval("$('#"+domElementID+"')."+widget-name+"('destroy')")

But we want to avoid using eval. How do we proceed, any help appreciated?

We are registering widget from _create (last statement in widget) and de-registering from _destroy. We need to process the said request for the widgets, which were not destroyed explicitly by developers.


Solution

  • I think what you are looking for is the bracket notation

    var widget = 'somename';
    $('#domElementID')[widget]('destroy');