I have a multiple select tag, and I need to write the function onclick of it\'s options, because I need to get the value of last clicked option, but when I wrote the followi
I liked @Reigel's (accepted) answer but needed to improve it for use in one of my projects. In the code below, I introduce a new function "findClickedOption" that accounts for the fact that maybe a user will re-click an already-selected option. This still doesn't account for CTRL-clicking multiple options but is good enough for me.
var multiselect_s=$('#ms2side__sx');
var options_s =multiselect_s.find('option:selected');
multiselect_s.live('click',function(){
var clickedOption =findClickedOption($(this), options_s);
options_s = $(this).find('option:selected');
doSomething(clickedOption);//call your own function here
});
function findClickedOption(selectbox, optionsArr){
var selectedOptions=selectbox.find('option:selected');
if(selectedOptions.size>1){
return selectedOptions.not(optionsArr);
}else{
return selectedOptions;
}
}