you can use document.activeElement
here is a simple example for this.
<head> <script type="text/javascript"> function GetActive () { if (document.activeElement) { var output = document.getElementById ("output"); output.innerHTML = document.activeElement.tagName; } } </script> </head> <body onclick="GetActive ();"> Click anywhere on the page to get the active element <input id="myInput" value="input field" /> <button>Sample button</button> <div id="output"></div> </body>
Pooja source share