Implement multiple selects with jQuery UI Selectable

HBCondo picture HBCondo · Dec 9, 2010 · Viewed 22.8k times · Source

can anyone help me use the jquery ui selectable library to perform the following functions:

  • Allow a user to select multiple items with a mouse click
  • De-select an item if it is already selected with a mouse click

Answer

Eric Skiff picture Eric Skiff · Jan 13, 2011

This is worked around in another question, but I'm reposting here for anyone who finds this via google. If you bind the "mousedown" event in jQuery and set metaKey there (as if the user is holding the ctrl/cmd key), then when you call selectable, it will already be set.

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