Search code examples
javascriptjqueryjquery-uijquery-widgets

How to find a div has a widget in Jquery?


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?


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).