jQuery UI Selectable - unselect selected item on click

fehays picture fehays · Oct 15, 2010 · Viewed 25k times · Source

Does anyone know if there's a way to configure a jquery ui selectable element to unselect the selected element when you click it? Sort of like a toggle. If it's already selected, unselect it, otherwise do the default behavior.

Thanks.

Answer

Keith Socheath Chea picture Keith Socheath Chea · Sep 26, 2012

i'm very late in responding to your question, but let me just answer it anyway so that to keep it as a reference for others.

$( ".selector" ).bind( "mousedown", function ( e ) {
    e.metaKey = true;
} ).selectable();

this will allow the toggle behavior that you're looking for.