HTML DOM focus() Method Last Updated : 13 Jun, 2023 Comments Improve Suggest changes Like Article Like Report DOM focus() method is used to give focus to an element and also to remove the focus with the help of blur() method. We can apply focus to any element and enable it by doing some operation. For example, we can give focus to some text by clicking a button. Syntax: Object.focus() Example-1: HTML <!DOCTYPE html> <html> <head> <title>DOM focus() Method</title> <style> input[type=text]:focus { background-color: red; } </style> </head> <body> <center> <input type="text" id="gfg" value="GeeksForGeeks"> <h2>DOM focus() Method </h2> <button type="button" onclick="geek()"> Submit </button> <script> function geek() { document.getElementById("gfg").focus(); } </script> </center> </body> </html> Output: Before applying focus: After applying focus: Example-2: HTML <!DOCTYPE html> <html> <head> <title>DOM focus() Method</title> <style> a:focus { background-color: magenta; } </style> </head> <body> <center> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>DOM focus() Method</h2> <a href="www.geeksforgeeks.com" id="geek">geeksforgeeks</a> <br> <button type="button" onclick="geeks()"> Submit </button> <script> function geeks() { document.getElementById("geek").focus(); } </script> </center> </body> Output: Before applying focus: After applying focus: Supported Browsers: The browser supported by DOM focus() method are listed below: Google Chrome 1.0 and aboveEdge 12.0 and aboveInternet Explorer 5.5 and aboveFirefox 1.5 and aboveOpera 8 and aboveSafari 3 and above Comment More infoAdvertise with us B bestharadhakrishna Follow Improve Article Tags : Technical Scripter Web Technologies HTML Technical Scripter 2018 HTML-DOM +1 More Similar Reads HTML DOM Style borderRadius Property The DOM Style borderRadius Property is used to set or return the four different borderRadius properties such as borderTopRightRadius, borderBottomRightRadius, and borderBottomLeftRadius of an element. It is used to add a rounded corner in an element. Syntax: It is used to get the border radius prope 2 min read HTML DOM getAttribute() Method The HTML DOM getAttribute() method is used to retrieve the value of a specified attribute from an HTML element. It returns the attribute's value as a string or null if the attribute doesn't exist.Note: It will return a null or an empty string if the specified attribute doesn't exist.SyntaxObject.get 2 min read HTML DOM parentElement Property The DOM parentElement property is used to return the parent element of a particular child element. It is a read-only property. The parentElement and parentNode properties are similar and the only difference is the parentElement property returns null if the parent node is not an element. Syntax: node 2 min read HTML DOM previousSibling Property The previousSibling property is used to return the previous node of the specified node as Node object or null if the specified node is the first in the list. It is a read-only property. Syntax: node.previousSibling Return value: This property returns a previous sibling of the specified node or null 1 min read HTML DOM innerText Property The DOM innerText Property is used to set or return the text content of a specified node and its descendants. This property is very similar to the text content property but returns the content of all elements, except for <script> and <style> elements. Syntax: It is used to set the innerT 2 min read HTML DOM nextSibling Property The nextSibling property returns the next node at the same tree level, providing a node object. It's read-only and navigates through sibling nodes within the document structure. Syntax: node.nextSiblingReturn value: Name Description Node The nextSibling property returns the next sibling node or null 2 min read HTML DOM isContentEditable Property The DOM isContentEditable property is used to return a boolean where true means the content of an element is editable and false represents content is not editable. This property is read-only. Syntax: Object.isContentEditable Return Value: This property returns a boolean value. true means that the co 1 min read HTML DOM implementation Property The DOM implementation property in HTML is used to return the DOMImplementation object associated with the current document. The DOMImplementation is the interface that represents a method providing the object which is not dependent on any particular document. Syntax: document.implementation Return 2 min read HTML DOM specified Property The DOM specified property is used to return the boolean value. It returns true if the element has a specified attribute, otherwise, it returns a false value if the element does not have a specific attribute. Syntax:attribute.specifiedReturn value: It returns the boolean value which represents wheth 2 min read HTML DOM offsetLeft Property The DOM offsetLeft property is used to return the left position in pixels. This position is relative to the left side of the offsetParent element. Syntax: element.offsetLeft Return Value: It returns the number representing the left position of the element in pixels. Example: In this example, we will 1 min read Like