I have an HTML select list that can have multiple selections:
<select id="mySelect" name="myList" multiple="multiple" size="3">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option> `
<option value="4">Fourth</option>
...
</select>
I want to get the option text every time I select it. I am using jQuery for this:
$('#mySelect').change(function() {
alert($('#mySelect option:selected').text());
});
It looks quite simple, however, if there are already some selected options in the favorites list, it will also return the text. As an example, if I had already chosen the Second option, after selecting the Fourth, the warning would bring me this - SecondFourth. So, is there a short, easy way with jQuery to get only the “current” selected option text, or do I need to play with strings and filter the new text?
source
share