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.
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.
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.
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.
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With