Question

How to check if the div has the widget or not ? for eg.

if we add a class to div we can check that using .hasClass like this, is there is any way to find widget is exists or not?

Was it helpful?

Solution

If you want to know if a div is currently used as a jQuery UI widget (which may be what you're asking, though I'm not entirely sure), you can check if the div has the "ui-widget" class.

$("yourDivSelector").hasClass("ui-widget")

Every jQuery UI widget has this class, and I believe most well-implemented third-party widgets use this class too (part of the CSS framework of jQuery UI).

OTHER TIPS

You're question is very difficult to understand. Since you've provided no code or explanation about your custom widget, it's also very difficult to answer. Based on your limited information, this is the best I can do...

Assign a CSS class to your widget (e.g. clsWidget). If the widget always has the clsWidget class, you can check for its existence like this:

if($("[DivThatMightContainWidgetSelector]").find(".clsWidget").length > 0) {
    //Div contains widget
}
else {
    //Div does not contain widget
}

The standard method to check if a widget was assigned to a tag, without checking if the tag has a widget class, is...

if ( !($("#myInput").data( "ui-fooWidget" ) )
   < widgetNotFound >
else
   < widgetFound >

Its a useful routine if you want to assign a different widget on certain devices, or to check if the widget has been initialised before calling a widget method etc.

All ui-widgets will store the root widget object in the data object assigned to the tag. This is also a used to access private widget methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top