HTML DOM hasFocus() Method
Example
Output some text if the document has focus:
var x = document.getElementById("demo");
if (document.hasFocus()) {
x.innerHTML = "The document has focus.";
} else {
x.innerHTML = "The document DOES NOT have focus.";
}
Try it yourself »
Definition and Usage
The hasFocus() method returns a Boolean value indicating whether the document (or any element inside the document) has focus.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
hasFocus() | 30.0 | 6.0 | 3.0 | Yes | 23.0 |
Syntax
document.hasFocus()
Parameters
None |
Technical Details
Return Value: | A Boolean value, incidating whether the document or any element in the document has focus:
|
---|