Met Document Hasfocus
# HTML DOM hasFocus() Method
[ Element Object](#)
## Example
Output text after the document gains focus:
```javascript
var x = document.getElementById("demo");
if (document.hasFocus()) {
x.innerHTML = "The document has focus.";
} else {
x.innerHTML = "The document has lost focus.";
}
[Try it Β»](#)
* * *
## Definition and Usage
The `hasFocus()` method returns a boolean value indicating whether the document (or any element within it) 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
```javascript
document.hasFocus()
## Parameters
None
## Technical Details
| Return Value: | A boolean value indicating whether the document or element has focus: * `true` - The document has focus * `false` - The document does not have focus |
| --- |
* * Element Object](#)
[](#)(#)
(#)[](#)
YouTip