2

I need a separate event if a select option is clicked by left vs right mouse button, something like this:

$('#sel').on('change', function(){
//if(changed using left button){console.log('left');}
//else if(changed using right button){console.log('right');}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id='sel'>
<option>lorem</option>
<option>ipsum</option>
</select>

This should happen only if the value is changed.

Any idea?

qadenza
  • 9,025
  • 18
  • 73
  • 126
  • https://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery – Julien Maret Jun 17 '20 at 06:01
  • @JulienMaret - see the post - `This should happen only if the value is changed.` – qadenza Jun 17 '20 at 06:13
  • Not sure if its even possible on `mousedown`. Let me know if you can get this done. – Always Helping Jun 17 '20 at 06:30
  • 1
    You could it be like that - $('#sel').on('change', function(){ $('#sel option').on('mousedown', function(e){ console.log(e.button); /** if it logs 0 then left click, if it logs 2 then it is right click */ }); }); But it can not be done on select options. see these posts - https://forum.jquery.com/topic/jquery-select-option-not-catching-mousedown-event-in-ie-and-chrome, https://stackoverflow.com/questions/13260958/mousedown-event-on-options-in-select-with-jquery-on – Alok Mali Jun 17 '20 at 06:39

0 Answers0