Get id of focused element using javascript

I have one Html page with many anchor elements. This single Html page contains many div parts. For now, only one part is displayed, and the anchor attached to that part will be focused. this html also contains a div for opening the popup. When this popup opens the binding specific to this will be focused. Now I want the anchor to be focused earlier on focus-focus. My code is as follows: -

<body onload="Main.onLoad();" onunload="Main.onUnload();">

        <a href='javascript:void(0);' id='anchor' onkeydown='Main.MainKeyHandler();'></a>
        <a href='javascript:void(0);' id='anchorAboutUs' onkeydown='Main.MainKeyHandler1();'></a>
        <a href='javascript:void(0);' id='anchorSecondScreen' onkeydown='Main.MainKeyHandler2();'></a>
        <a href='javascript:void(0);' id='popupanchor' onkeydown='PopupKeyHandler();'></a>
        <div id="ParentDiv">
            <div id="SplashScreenDiv">
                <div id="SplashScreen"></div>
            </div>
            <div id="Logo"></div>
            <div id="Header"></div>
            <div  id='messagePopup'  style='position:relative;width:500px;z-index:1000;background-color:#ffffff;'><div ></div ><div id='popupReturn'>Return</div><div>
            <div id="PopUp">
                <div id="YesBtn"></div>
                <div id="NoBtn"></div>
            </div>
            <div id="FirstScreen">
            <div id="testinfo" style="color:#ff0000; width:600px; height:50px; overflow:hidden; font-size:xx-large; "></div>
                <div id="btn_horoscope"></div>
                <div id="btn_aboutus"></div>
            </div>
            <div id="AboutUsScreen" >
                <div id="AboutUsImgDiv">
                    <div id="AboutUsImg"></div>
                </div>
                <div id="aboutUsInfoDiv">
                    <div id="aboutUsInfo"></div>
                </div>
            </div>
            <div id="SecondScreen" >
                <div id="HoroscopeImg" class="HoroImage"></div>
                <div id="SelSunSignMsgDiv">
                    <div id="SelSunSignMsg">Select your SunSign </div>
                </div>
                <div id="SelSunSignDiv">
                    <div id="SelSunSign">
                    <div id="SunSign_0"></div>
                    <div id="SunSign_1"></div>
                    <div id="SunSign_2"></div>
                    <div id="SunSign_3"></div>
                    <div id="SunSign_4"></div>
                    <div id="SunSign_5"></div>
                    <div id="SunSign_6"></div>
                    <div id="SunSign_7"></div>
                    <div id="SunSign_8"></div>
                    <div id="SunSign_9"></div>
                    <div id="SunSign_10"></div>
                    <div id="SunSign_11"></div>
                    </div>
                </div>

            </div>
        </div>


    </body>

      

any help would be indicated

+3


source to share


1 answer


You need document.activeElement.id

. You can find more information here , which has been criticized previously.



+16


source







All Articles