I have a select element in my HTML:
<select id="dropdown">
<option value="1">First</option>
<option value="2">Second</option>
</select>
It renders as a drop-down menu, which, when the user clicks it, (surprise!) drops down. In order for the page to be used via keyboard only, I wish to make it so that the menu drops down when the user presses a key.
$('body').keypress(function(event) {
var key = String.fromCharCode(event.which);
if (key == 'a') {
$('#dropdown').doSomething(); // ?
}
});
The best I've found is to invoke focus()
. It allows to select the value via keyboard, but it doesn't drop down the menu. Is there a way to make the menu drop down?