HTML | DOM activeElement Property

The DOM activeElement property is used to return the currently active elements in the HTML document. This property is read-only. It gives the reference of focused element object in the document.

Syntax:

document.activeElement

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <style>
            h1 {
                color:green;
            }
            body {
                text-align:center;
            }
        </style>
        <script>
            function GFG() {
  
                // Get Active Element using activeElement
                // property and assign it value equal to 
                // to its tag
                var x = document.activeElement.tagName;
                document.getElementById("geeks").innerHTML = x;
            }
        </script>
    </head>
    <body onclick="GFG()">
        <h1>GeeksforGeeks</h1>
        <h2>DOM activeElement property</h2>
        <input type="text" placeholder="GeeksforGeeks">
        <button>Submit</button>
        <p id="geeks"></p>
    </body>
</html>                                

chevron_right


Output:

Supported Browsers: The browser supported by DOM activeElement property are listed below:

  • Apple Safari 4.0
  • Google Chrome 2.0
  • Firefox 3.0
  • Opera 9.6
  • Internet Explorer 4.0


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.