1

Please help

I have a

<select id="select">
  <option></option>
  <option></option>
  <option></option>
<select>

I used jquery to detect arrow up/arrow down for select and it worked

$(document).on('keyup', '#select', function () {
    console.log('key-up');
});

But I clicked on select and a dropdown is opened, I used arrow up/arrow down to select in that drop-down but this function above not work! I changed it to:

$(document).on('keyup', '#select option', function () {
    console.log('key-up');
});

But it not work? How can i detect event in this case

dan1st
  • 12,568
  • 8
  • 34
  • 67
  • See [Check if select is displaying options](https://stackoverflow.com/a/30729795/924299) and [jQuery keypress/keyup/etc events not fired when select box is expanded](https://stackoverflow.com/questions/8648990/jquery-keypress-keyup-etc-events-not-fired-when-select-box-is-expanded). – showdev Apr 15 '20 at 04:54

1 Answers1

0

i think that what you want is:

$('#select').on('keyup', function(event) {
    if(event.which === 38) { // arrow up
       // do what you want
    }
    if(event.which === 40) { // arrow down
       // do what you want
    }
});
Ebergsma
  • 1
  • 1