4

I need the option element the user clicked on in a multiple select control in Internet Explorer. StackOverflow helpfully suggested these questions:

Get clicked option in multiple dropdown

How to get clicked option value of a multiple select, fired by .change() event

but neither one works in Internet Exploder.

example 1: https://jsfiddle.net/c8q956dr/

  $("body").on("click", "select[multiple]",
               function(e)
               {
                   log("click: "+ e.target.value);  
               });

this one works by attaching the click event to the select element, and works perfectly in Chrome/Firefox, as they return the option the user clicked in the event.target member. IE, on the other hand, returns the entire select element and offers no indication which option was clicked.

example 2: https://jsfiddle.net/55up15Lb/1/

  $("select option").click(  
               function(e)
               {
                   log("click: "+ this.value);  
               });

this one works by attaching the click event handler directly to the option elements, but I cannot get it to work at all in IE.

I've tried IE 8, 9, and 11. am I stuck?

Community
  • 1
  • 1
Dave Thieben
  • 5,348
  • 2
  • 27
  • 37
  • Options don't reliably fire mouse events, you should be getting the selects value instead, or at least just the selected options, there shouldn't be a need for getting the clicked option. – adeneo May 22 '15 at 20:45
  • I need to select other list items when certain other list items are selected. – Dave Thieben May 23 '15 at 00:58
  • yes, sorry, should have mentioned I need Ctrl+Click to work. – Dave Thieben May 23 '15 at 15:52
  • In other browsers you can check if clicked option is selected by event.originalTarget.selected but I don't know how it can happens in IE also – Jakub G Sep 25 '19 at 08:13

0 Answers0