Is there a way to determine if a <select> dropdown menu is open?
- by Robert
I'm looking for a way to determine if/when a <select> element's menu is open. I don't need to force it to open or close, just figure out if it's open or closed at a given time.
I can listen to events for focus/blur, mouseup/mousedown, etc., but I don't think I can reliably figure out the state of the menu from those events. For example, mousedown followed by mouseup could mean the user clicked and dragged to a selection and released (in which case the menu is now closed) or clicked and released to open the menu (in which case the menu is open). It also seems likely that the specific behavior of dropdown menus is browser-dependent.
I know I could do this if I roll my own dropdown menu, but I prefer to use <select>.
Is there a reliable way to find out if a dropdown menu is open? Or is this something that Javascript can't know?