Javascript examples for DOM:Document activeElement
The activeElement property returns the currently focused element in the document.
This property is read-only.
A reference to the element object that has focus
The following code shows how to get the currently focused element in the document:
<!DOCTYPE html> <html> <body onclick="myFunction()"> <p>Click anywhere to display the active element.</p> <input type="text" value="An input field"> <button>A Button</button> <p id="demo"></p> <script> function myFunction() {//from w w w. j ava 2 s .c om var x = document.activeElement.tagName; document.getElementById("demo").innerHTML = x; } </script> </body> </html>