Reputation: 1357
I have a list box with 10 elements. now the element 5 is selected. If i change the value to 8 then i need to get both 5 and 8.
i.e I need the currently selected item and previous selected item.
Is there any possibility in Jquery. Please do the needful. Thanks
Upvotes: 1
Views: 759
Reputation: 337580
Try this:
// on load
$("#mySelect").data("previous-value", $("#mySelect").val());
// on change
$("#mySelect").change(function() {
var previousValue = $(this).data("previous-value");
// do things with the previous value
// update previous value
$(this).data("previous-value", $(this).val());
});
Upvotes: 3