0

I need, when I click in a multiple select list option to transform a mouse "click" in a "ctrl + click" to select multiple itens.

Now I'm doing this:

$(document).on("mousedown", '.CentroCusto_new option', function (e) {
    this.selected = !this.selected;
    e.preventDefault();
});

But this code didn't work on Internet Explorer because IE can't 'find' the selector 'option'.

Then I want to try to do this in another way and I need to know how to simulate ctrl + click when I click.

Joao Paulo
  • 1,083
  • 4
  • 17
  • 36
  • Which IE? and aslo possible duplicate of [Check Ctrl / Shift / Alt keys on 'click' event](http://stackoverflow.com/questions/2847135/check-ctrl-shift-alt-keys-on-click-event) – zero298 Mar 13 '14 at 21:04

1 Answers1

0

If ctrl is clicked the event.ctrlKey is true (in your case e.ctrlKey;)

$(document).on("mousedown", function (e) {
    console.log(e.ctrlKey); // it's boolean
});
Mr.TK
  • 1,743
  • 2
  • 17
  • 22
  • Should be keydown rather than keypress. Also, not all keys trigger keypress events in all browsers. – Sam Mar 13 '14 at 21:14
  • yeah... was thinking keydown... typed keypress :) My bad. It worked for me. ;) Maybe there is an info in EVENT data of event? :D function(event) {} <--- this event ;) Googled a bit ;D TRY THIS: event.ctrlKey – Mr.TK Mar 13 '14 at 21:17
  • Information on events in javascript can be found on http://www.w3schools.com/js/js_events_examples.asp and http://www.w3schools.com/jsref/dom_obj_event.asp – Sam Mar 13 '14 at 21:19