How to get clicked parameter value for multiple selection raised by .change () event

I have several favorites lists:

<select id="List" multiple="multiple">  
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>

I fire the event when I select:

$("select#List").change(function() {
    // do ajax stuff...
});

I need to get the value of the clicked parameter that triggered the change event.

Example: if option 1 is already selected, and I select "option 2" that fires the .change () event, I want to get the value "option 2".

(I already read this post Get a click in a few drop-down lists , but this does not work for me).

-2
source share
1 answer

What doesn't work for you, I checked the answers in the link you posted and it works.

. : http://jsfiddle.net/unkxt8h3/

, , - , . , , peacy;)

HTML:

<select id="List" multiple="multiple">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>

JS:

$("#List option").click(function () {
    var value = $(this).attr("value");
    console.log(value);
    alert(value);
});
+2

Source: https://habr.com/ru/post/1589510/


All Articles