Programmatically 'unselect' a jQuery UI selectable widget

Derek Adair picture Derek Adair · Dec 20, 2010 · Viewed 9k times · Source

Is there a way to programmatically 'unselect' any and all selected elements for a given $("#selectable").selectable() widget?

Answer

Alexander Bird picture Alexander Bird · Dec 20, 2010

The following command works at http://jqueryui.com/demos/selectable/

$('#selectable .ui-selected').removeClass('ui-selected')

Since a class's existence defines if an item is selected, simply removing the item will deselect it.

Note, you can also take advantage of toggleClass and addClass functions.

EDIT:

Try this too: $('#selectable').trigger('unselected'). That might also trigger all the css changes as well, and this way the unselected event also gets triggered for whatever else may be hooked to it.