0

I have a <select> that would like to respond to a click event (using javascript). On MacOS Chrome, no event is fired on click. This is a known problem (e.g. 1, 2, …)

Example

<select id='hodor'>
    <option>Jon Snow</option>
    <option>Joffrey</option>
</select>

and

$('#hodor').on('click change', function (e) {
    $(this).after("<li>"+e.type+"</li>");
});

I already know that I can use the change event (which I already do use). However the behavior is different for the end user and I need to make it work accurately: as soon as my select is clicked, I would like my UI to do something — not only when the selected option is changed.

What are my alternatives?

Kindly note: this is not a duplicate of other questions which allow for a "use the change event" answers. That's not what I am asking.

Community
  • 1
  • 1
Sklivvz
  • 30,601
  • 24
  • 116
  • 172

1 Answers1

-1

Use the mousedown event:

$('#hodor').on('mousedown', function (e) {
    $(this).after("<li>"+e.type+" " + $("option:selected", this).val() + "</li>");
});

Note that this fires before the user can select another option in the menu -- .val() returns the current value. I tried using mouseup, but that didn't fire.

FIDDLE

Barmar
  • 741,623
  • 53
  • 500
  • 612