Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HTML Select multiple without ctrl key
/**
* DWTFYW License
* Author: Tony Brix, http://tonybrix.info
*
* Set all multiple select elements to allow selecting multiple without using the ctrl key
*
*/
(function($){
$.fn.selectMultiple = function(){
return this.mousedown(function(e){
e.preventDefault();
//save scrollTop to prevent scrolling on selection change.
//see: http://stackoverflow.com/questions/24543862/selecting-multiple-from-an-html-select-element-without-using-ctrl-key/
var scroll = this.scrollTop;
e.target.selected = !e.target.selected;
this.scrollTop = scroll;
$(this).focus();
}).mousemove(function(e){e.preventDefault()});
};
})(jQuery);
$("select[multiple]").selectMultiple();
@albertoha94

This comment has been minimized.

Copy link

@albertoha94 albertoha94 commented Jul 6, 2016

Tried it and didn't work :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment