HTML DOM activeElement Property



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

 Live Demo

<!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 −

Updated on: 2019-07-30T22:30:26+05:30

201 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements