-1

Is there a way to trigger the same option once again and get an alert:

  $(document).on('change', '.item-select', function() {
    
    var optionValue = $(this).val();
    alert(optionValue);

  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


 <select class="item-select">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select> 

I want to click on Saab and get an alert Saab and then immediately click on Saab again and get an alert.

peace_love
  • 6,229
  • 11
  • 69
  • 157

1 Answers1

1

Add a blank value and reset the select which won't trigger the change event.

I think you've already asked this question here.

$(document).on('change', '.item-select', function() {
  var optionValue = $(this).val();
  $('option', this).first().prop('selected', true)
  alert(optionValue);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<select class="item-select">
  <option>Select make...</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
Cue
  • 2,699
  • 1
  • 12
  • 13
  • This isn't always possible depending on the UI requirements. Plus it's not required as it's possible to do what the OP needs without adding redundant options. See the duplicates for more details. – Rory McCrossan Jan 18 '19 at 15:49
  • I understand that. But the OP hasn't ruled it out considering the link to the same question in my answer gives more clarity on what the OP is trying to achieve. – Cue Jan 18 '19 at 16:19