views:

71

answers:

2

Is it possible to use shift and mouse click to select multiple elements on a page using jquery?

I have several divs that i have given a tabindex to so that i can select them and can do things like delete them etc.

I want to be able to select more than 1 by holding down shift and using the mouse to click on each div and am struggling to do this.

Does anyone know how this can be done?

A: 

Sure, if you are willing to do some work :)

Listen for the shift keydown, set a var that you can access from within your click handler functions, if the var is set then add that item, (or their tabindex for your current implementation) to your list of items to operate on when an 'action button' is pressed.

unset the var when you get the shift keyup event.

unomi
+1  A: 

It sounds like jQuery UI Selectable is what you're after, you can try it out here.

To stay with OS conventions, they key it uses is Ctrl and not Shift, this isn't an option you can change without changing the jQuery UI code itself. It also has the feature of click and drag over elements to get a rectangular selection as well...if that's of any use.

Nick Craver