views:

26

answers:

2

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

+1  A: 

@Boycs: As per my understanding, using Widget Factory protects you from instantiating a plugin multiple times on the same element. (ref: http://jqueryui.pbworks.com/widget-factory)

In addition if you want to confirm if "container" is already an investment grid you can try the following option from inside your plugin code:

this.element.data("investmentGrid") === this;

For more details you can refer to docs.jquery.com/UI_Developer_Guide

Assign Labs
Thanks... I may not have been clear in my initial question... I need to be able to determine from outside of my plugin code whether or not $('#container') is already an investmentGrid or not...
Boycs
Can you share with me why you would need to establish whether "container" is already an investmentGrid or not? It will help me answer more accurately. Thanks
Assign Labs
+1  A: 

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

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