Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body onclick="myFunction()"> <h1>The Document Object</h1> <h2>The activeElement Property</h2> <input type="text" value="An input field"> <button>A Button</button> <p>Click anywhere in the document to display the active element:</p> <p id="demo"></p> <script> function myFunction() { const element = document.activeElement.tagName; document.getElementById("demo").innerHTML = element; } </script> </body> </html>