This following code snippet is to avoid the need for ctrl-click in a multi-select box
but it does not work in IE 8 .
Is there any work around to achive the same in IE and other IE version?
$('option').mousedown(function(e) {
e.preventDefault();
$(this).prop('selected', !$(this).prop('selected'));
return false;
});
I found one major issue with jQuery answer above. The
.val()
of the$(select)
won't update.Here is working solution:
I don't believe there's any way to get the
mousedown
orclick
event on anoption
element in IE8.If you really want the behavior you describe, I suggest that you use a different control, rather than a multiple
select
box. Changing the behavior of standard UI components is usually not a good idea, as users are used to them behaving a certain way and get confused when they behave differently in some apps/pages than they do in others. If you want a list with simple click-on, click-off behavior, much better to do something completely your own.You can do this with a multiple
select
, but the user experience is really ugly:Live Example | Source
Again, though, that's a really ugly user experience.
Here's an example of a pseudo-select instead: Live Example | Source
CSS:
HTML:
JavaScript using jQuery:
That's just something I dashed off in a couple of minutes, obviously plenty of room for improvement, but you get the idea.
Note: If you use something like this, you'll want to detect mobile browsers and browsers using assisstive technologies (screen readers, etc.) and use a normal
select
instead (as the browser will do a better job of working with the user in those situations.).