The HTML DOM activeElement property is a read-only property to return the currently focused element in the document.
Following is the syntax −
document.activeElement
Let us now see an example to implement the DOM activeElement property −
Example
<!DOCTYPE html> <html> <body onclick="display()"> <h2>Heading Two</h2> <p>Click in the element to get the active element.</p> <input type="text" value="Enter text..."> <p id="myid"></p> <script> function display() { var a = document.activeElement.tagName; document.getElementById("myid").innerHTML = a; } </script> </body> </html>
Output
Now, click the element to display the same currently active element −