Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a jQuery UI plugin is attached to an element?

How can I check to see if a jQuery UI plugin is attached to an element? For example, if I load up the .sortable widget, how can its presence be determined?

The purpose behind this question is that I would like the ability to toggle .sortable on elements. With the ability to see that .sortable is present, I could then call .sortable('destroy') to remove it.

like image 453
Jay Avatar asked Nov 05 '09 08:11

Jay


People also ask

How do I know if jQuery UI is loaded?

To avoid needing to catch an error, you can check typeof jQuery — it will return "function" if jQuery is loaded, and "undefined" if it is not.

Is jQuery UI dependent on jQuery?

jQuery UI is a widget and interaction library built on top of the jQuery JavaScript Library that you can use to build highly interactive web applications.

Is jQuery UI plugin?

jQuery UI is built for designers and developers alike. We've designed all of our plugins to get you up and running quickly while being flexible enough to evolve with your needs and solve a plethora of use cases. If you're new to jQuery UI, check out our getting started guide and other tutorials.

What is the difference between jQuery and jQuery ui?

JQuery is basically the base of JQuery UI and is the more powerful between the two. It should be used for more advanced work that requires custom code and interactions. For basic user interface needs, using the JQuery UI is very beneficial as it reduces the complexity of coding and speeds up the entire process.


1 Answers

All ui widgets attach their name as true to the element's container data. jqueryui also adds a data filter expression.

var $elem = $('div.sortable-container:data(sortable)');
if ($elem.length){
  // $elem contains list of elements that have sortable widget attached
}
like image 89
Corey Hart Avatar answered Nov 15 '22 20:11

Corey Hart