HTML DOM Document hasFocus() method
- Previous Page getElementsByTagName()
- Next Page head
- Go to the Previous Level HTML DOM Documents
Definition and usage
If the document (or any element within the document) has gained focus, then hasFocus()
The method returns true
.
Otherwise returns false
.
Example
Show if the document has focus:
if (document.hasFocus()) { text = "The document has focus."; } text = "The document does NOT have focus."; }
Syntax
document.hasFocus()
Parameter
None.
Return value
Type | Description |
---|---|
Boolean |
Returns true if the document (or an element within the document) has focus. Returns false otherwise. |
Browser support
All browsers support document.hasFocus()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous Page getElementsByTagName()
- Next Page head
- Go to the Previous Level HTML DOM Documents