HTML DOM hasAttributes() Method Last Updated : 15 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The HTML DOM hasAttribute() method is a boolean function that returns either true or false but not both. This method returns a true value if the element contains an attribute otherwise, it returns false. It is very useful to know whether the element in the document has attributes or not. Syntax: node.hasAttributes() Parameters: It does not contain any parameter. Return Value: It returns true if the element contains an attribute otherwise it returns false. Example 1: In this example, we will see that the hasAttribute() comes out to be true when we have an attribute in our body. HTML <!DOCTYPE html> <html> <head> <title> DOM hasAttributes() Method </title> </head> <body id="geeks"> <center> <h1 style="color:green;width:50%;" id="sudo"> GeeksForGeeks </h1> <h2>DOM hasAttributes() Method </h2> <p>Click on the button to check if that body element has any attributes</p> <button type="button" onclick="geeks()"> Submit </button> <script> function geeks() { let s = document.body.hasAttributes(); document.getElementById('gfg').innerHTML = s; } </script> <p id="gfg"></p> </center> </body> </html> Output: Example 2: In this example, the hasAttribute() returns false as there is no attribute in our head. HTML <!DOCTYPE html> <html> <head> <title> DOM hasAttributes() Method </title> </head> <body> <center> <h1 style="color:green;width:50%;" id="sudo"> GeeksForGeeks </h1> <h2>DOM hasAttributes() Method </h2> <p>Click on the button to check if that head element has any attributes</p> <button type="button" onclick="geeks()"> Submit </button> <script> function geeks() { let s = document.head.hasAttributes(); document.getElementById('gfg').innerHTML = s; } </script> <p id="gfg"></p> </center> </body> </html> Output: We have a complete list of HTML DOM methods, to check those please go through this HTML DOM Object Complete reference article. Supported Browsers: The browser supported by DOM hasAttributes() method are listed below: Google Chrome 1 and aboveEdge 12 and aboveInternet Explorer 8 and aboveFirefox 1 and aboveOpera 12.1 and aboveSafari 1 and above We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript. Comment More infoAdvertise with us B bestharadhakrishna Follow Improve Article Tags : Technical Scripter Web Technologies HTML Technical Scripter 2018 Web technologies HTML-DOM +2 More Similar Reads HTML DOM scrollTop Property The DOM scrollTop property is used to return or set the number of pixels an element is scrolled vertically. If the element's content doesn't generate a scroll bar, then its scrollTop value is 0. Syntax: It returns the scrollTop property.element.scrollTopIt is used to set the scrollTop propertyelemen 2 min read HTML DOM isSameNode() Method The isSameNode() method checks whether the two nodes are the same or not. This method is different from isequalNode(), where two different nodes can be equal but not the same, here the same node means that they are referencing the same object. Syntax: node.isSameNode(othernode) Parameters: The "othe 1 min read HTML DOM console timeEnd() Method The console.timeEnd() method in HTML is used to end a timer started by the console.time() method. This can be used to calculate the time of certain operations for testing purposes. Syntax:console.timeEnd( label )Parameters: This method accepts single parameter label which is optional. It is used to 3 min read HTML DOM getAttributeNode() Method The getAttributeNode() method in HTML DOM is used to return the attribute node with the specified name of an element, as an attribute object. This function is similar to the getAttribute() method but the only difference is that the getAttribute() method returns the value of an attribute node, not an 2 min read HTML DOM scrollWidth Property The DOM scrollWidth property is used to return the width of an element. This property includes padding and also content that is not visible on the screen due to overflow but does not include a border, scrollbar, or margin. It is a read-only property. Syntax: element.scrollWidth Return Value: It retu 1 min read HTML DOM cloneNode() Method The HTML DOM cloneNode() Method is used to copy or clone a node on which the cloneNode() method is called. For example, a list item can be copied from one list to another using this method.Syntax: yourNode.cloneNode([deep]) Parameters: The [deep] is an optional argument. We can set its value to "tru 3 min read HTML onunload Event Attribute The onunload event attribute works when the document is being unloaded i.e. it occurs when the browser has been closed. It is mostly used when the user opens a link and submits the form and closes the browser window. Basically, it is: Fired when a user navigates away from a page or closes the browse 1 min read HTML DOM exitFullscreen() Method The exitFullscreen() method requests the element which is currently in full-screen mode to be taken out of full-screen mode. If the element is not in full-screen mode, then nothing gets changed. The reverse of this method is requestFullscreen(). Syntax: HTMLElementObject.exitFullscreen() Parameters: 1 min read HTML DOM children Property The DOM children property is used to return an HTML collection of all the child elements of the specified element. The elements in the collection can be accessed by index numbers. It differs from childNodes as childNodes contain all nodes (i.e. it includes text and comment nodes as well) but on the 2 min read HTML DOM button Object The button object in HTML is used to represent a <button> element. The getElementById() method is used to get the button object. Property Values:Property ValuesDescriptionautofocusSets or returns whether a button should automatically get focused on page load.defaultValueSets or returns the def 3 min read Like