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

Since jQuery UI 1.8, special selectors are being added to Sizzle for each widget. These are in the form of :ui-widgetname.

To check for the presence of a sortable widget on an element, you can therefore use:

if(element.is(':ui-sortable')) {
    element.sortable('destroy');
}

If anyone is looking for this solution in later jqueryUI versions, the data container's name of sortable plugin is now uiSortable and not sortable. Im using jQueryui 1.10

i.e to find elements u can use

var $elem = $('#sortable-container:data(uiSortable)');

and to find elements that are NOT yet initialized

var $elem = $('#sortable-container:not(:data(uiSortable))');

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
}