Latest web development tutorials

HTML DOM hasFocus () method

Elements Object Reference Element object

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.";
}

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:

  • true - documentation for focus
  • false - Document not get focus

Elements Object Reference Element object