JavaScript document.hasFocus() Method

You are Here:

JavaScript document.hasFocus() Method

The document.hasFocus() method returns a Boolean value indicates whether the document or any element inside the document has focus.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> setInterval("myFunction()", 1); var x = document.getElementById("point"); function myFunction(){ if(document.hasFocus()) x.innerHTML = "The document has focus."; else x.innerHTML = "The document does not have focus."; } </script> </body> </html>

Syntax

document.hasFocus()

Return Values

ValueExplanation
trueif the active element in the document has focus.
falseif the active element in the document has no focus.

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author