I have a <select multiple="multiple" id="multi">
in my website, and I have a script in jquery that has this function:
$("#multi").on("change",function(){})
I want to access the latest selected item of the select
in this function(the last one selected by user), how can I do that?
FIDDLE :
Less coding with Optimize solution : Why not use the
is
function of jquery:How about this
You can use
:selected
selector and:last
(or alternatively.last()
) this way:JSFiddle
To get the last selected by the user, you can do this
FIDDLE
I think you are searching for this
DEMO
define global variable, and every time ur dropdown change the seletion, u can replace the last selected value with the new one.