javascript – Get the value of the "option" that was clicked either to select/deselect


I have the following <select> :

<select id="multiselect" multiple="multiple">
  <option value="pedra">Pedra</option>
  <option value="papel">Papel</option>
  <option value="tesoura">Tesoura</option>

With the Jquery code below, I can get the value of the last selected <option> :

<script type="text/javascript">
  $(document).ready(function() {

    $(document).on('change','#multiselect', function(){

        console.log (( $('option', this).filter(':selected:last').val() ))

However, what I really wanted was to get the value of the clicked <option> (I know that on('click', func..) will not work in this case), regardless of whether it is being selected or deselected.

I searched a lot, but the most I found was how to find the value of the last one selected.

The plugin used is Bootstrap-multiselect


Try using like this:

$("#multiselect").on("multiselectclick", function (event, ui) {


I found this in the documentation :

$("#multiselect").on("multiselectclick", function(event, ui) {
  /* event: the original event object
     ui.value: value of the checkbox
     ui.text: text of the checkbox
     ui.checked: whether or not the input was checked or unchecked (boolean)
Scroll to Top