Get Clicked Option In Multiple Dropdown August 29, 2022 Post a Comment I have a multi select dropdown eg: Opt #1 Solution 1: You can get it in the click handler for each option element: $("#myList option").click(function() { var clickedOption = $(this); }); Copy Update EDIT: As I manipulate the list inside a change event, I can't do it in a click event. In that case you need to delegate the event using on. Try this: $("#myList").on("click", "option", function() { var clickedOption = $(this); }); Copy One thing to note, however, is that option elements will not raise click events at all in IE, so neither of the above will not work in that browser. Solution 2: As you know, If the user clicked on opt #4 without Cntrl key pressed, then you will only get Opt#4 as the selected option. If the user clicked on opt #4 with Cntrl key pressed, then all three options will be selected. So all three options will be returned. If you want only Opt#4, then you would need to add a click event handler. Solution 3: Would something like the following help you? $('#myList').delegate('option', 'click', function (opt) { alert('Option ' + opt.value + ' was clicked'); }); Copy Solution 4: The real answer: select.onclick = function(e) { console.log(e.target.value); }; Copy Share Post a Comment for "Get Clicked Option In Multiple Dropdown"
Post a Comment for "Get Clicked Option In Multiple Dropdown"