I have an html select:
<select> <option>Choose one</option> </select>
Using jQuery, is there an event that I can capture when a list of selection options was displayed? (the reason why I need this is because I want to postpone the list population until the list should be displayed to the user).
mousedown
works when it clicks on it, but does nothing if they click on it and press the enter key.
focus
also works for clicking and almost works for tabbing to it, but it starts immediately when you click on it, and does not wait until they press the enter button to open the list of options. (This is a problem because if they are inserted into it and then inserted without pressing the enter key, I do not want the event to fire).
I even came up with this abomination:
var select_reveal = function(ev) { ... } $('select').on('mousedown', select_reveal).on('keydown', function(ev) {
It actually works . This even works for the case when they type the letter of the alphabet (it fills the list, and then goes to the first option, starting with that letter). But, as I said, this is more an abomination. It is also a bit hacked, just checking the βtabβ as an exception - there are certain other exceptions that won't trigger a selection.
Is there a simple event that covers this use case (or at least something less disgusting that covers it)?
(Note. I know that there are alternatives to structuring the system, for example, by populating options ahead of time, because they change, not the choice, but I'm not looking for alternative suggestions, just wondering if there is a clear solution to the problem).