Is there a way to determine if a <select> dropdown menu is open?
Posted
by Robert
on Stack Overflow
See other posts from Stack Overflow
or by Robert
Published on 2010-04-25T18:59:30Z
Indexed on
2010/04/25
19:03 UTC
Read the original article
Hit count: 281
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?
© Stack Overflow or respective owner