hello, have some divs, on some positions. i want select them with mouse, like when are you selecting object in photoshop. so i want to select group of divs. is that possible with jquery ? thanks
views:
398answers:
3
+1
A:
You can simulate a selected effect by changing the classes of the divs, e.g.:
$('div.selectable').click(function() {
$(this).addClass('.selected');
});
If you want the div to get unselected after is has been clicked again, you can do something like:
$('div.selectable').click(function() {
if($(this).is('.selected')) {
$(this).removeClass('.selected');
} else {
$(this).addClass('.selected');
}
});
or more concisely with the ternary operator:
$('div.selectable').click(function() {
var $div = $(this);
$div.is('.selected') ? $div.removeClass('.selected') : $div.addClass('.selected');
});
karim79
2009-08-17 12:13:43
+2
A:
There's jQuery Drag to Select, which will probably solve your problems.
JorenB
2009-08-17 12:23:45
thanks jorenb, that looks nice :)
mm
2009-08-17 12:25:16
Good luck with it ;-)
JorenB
2009-08-17 12:35:15
have problems to work with it, somebody know how run that example which is on that site ?
mm
2009-08-17 13:40:36
ok, already know..
mm
2009-08-17 13:42:22
anyway, does somebody know, how to use it with divs ? it works only with ul and li ? thanks
mm
2009-08-17 13:53:01
As far as I can see from the examples, you'll need to do this: `$('#parent-element').dragToSelect(selectables: 'div')`, but I can't be 100% sure... Hold on.
JorenB
2009-08-17 13:59:39
Yeah, that should do it. If you want to make more types of elements selectable, comma-separate them: `div, li, tr` (the plugin inserts this string straight into a jQuery, so you could use virtually any supported CSS3-selector =D )
JorenB
2009-08-17 14:03:05