English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM hasFocus() Method

HTML DOM Document Object

hasFocus()The method returns a boolean value that is used to detect whether the document (or any element within the document) has focus.

Syntax:

document.hasFocus()
var x = document.getElementById("para");
if (document.hasFocus()) {
x.innerHTML = "The document has focus.";
}
x.innerHTML = "The document does not have focus.";
}
Test See‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the hasFocus() method:

Method
hasFocus()303YesYes6

Technical Details

Return value:Returns false if the active element in the document does not have focus; returns true if the active element in the document has focus.

HTML DOM Document Object