I have a multi select dropdown eg:
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.
You can get it in the click handler for each option element:
$("#myList option").click(function() {
var clickedOption = $(this);
});
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);
});
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.
Would something like the following help you?
$('#myList').delegate('option', 'click', function (opt) {
alert('Option ' + opt.value + ' was clicked');
});