How to check if a div element is focused

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Panos Antoniad
    New Member
    • Oct 2010
    • 3

    How to check if a div element is focused

    Hello,

    I am searching for a way to check if a div is in focus or not (something like the focused property of the input elements).


    The reason is that I have created the following scrollable select area using div:

    <div id="scrolldiv" style="border : solid 2px grey; padding:4px; width:300px; height:180px; overflow:auto;" >
    <div onclick='highli ghtOption(this. id)'></div>
    ...
    </div>

    Everything works fine and I can now put anything I want in the separate options (unlike the standard select form). What I have lost is the ability to move up/down the select area with up/down key arrows.

    I know how to capture the keyup/keydown events but I don't know how to check if the scrolldiv is in focus in order to move up/down the selection before passing the event to the scrolling function.
Working...