Search code examples
jquery-uiwidget

Determine if an element is a jQueryUI Widget


I have written a jquery-ui widget using the Widget Factory...

I need to be able to determine in code whether the element is already a widget or not...

My investmentGrid widget is created on #container with

 $('#container').investmentGrid()

I need to be able to determine elsewhere in the code if $('#container') is already an investmentGrid


Solution

  • You can query the element's jQuery.data() function, like so:

    if ($('#container').data('investmentGrid')) {
       ...
    }