HTML DOM activeElement Property
The DOM activeElement property helps us find which element is currently active on a webpage. This feature only allows us to read information and can't be changed. It shows us the focused element on the webpage.
Syntax:
document.activeElement
Return Value: A mention of the focused element in the document.
Example: In this instance, we'll work with something called the "DOM activeElement property."
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
h1 {
color: green;
}
</style>
</head>
<body onclick="GFG()">
<h1>Propertutorials</h1>
<h2>DOM activeElement property</h2>
<input type="text" placeholder="Propertutorials" />
<button>Submit</button>
<p id="result"></p>
<script>
function GFG() {
// Get Active Element using activeElement
// property and assign it value equal to
// its tag
let x = document.activeElement.tagName;
document.getElementById("result").innerHTML = x;
}
</script>
</body>
</html>