HTML DOM hasFocus () method
Examples
After obtaining the focal point in the document output textual information:
var x = document.getElementById ( "demo" );
if (document.hasFocus ()) {
x.innerHTML = "document has to get the focus.";
} Else {
x.innerHTML = "document loses focus.";
}
if (document.hasFocus ()) {
x.innerHTML = "document has to get the focus.";
} Else {
x.innerHTML = "document loses focus.";
}
try it"
Definitions and use
hasFocus () method returns a Boolean value, for detecting a document (or any element within the document) whether to acquire focus.
Browser Support
Figures in the table represent the first browser to support the method version number.
method | |||||
---|---|---|---|---|---|
hasFocus () | 30.0 | 6.0 | 3.0 | Yes | 23.0 |
grammar
document.hasFocus ()
parameter
None |
Technical Description
return value: | Boolean value, for detecting whether the document or element gain focus:
|
---|