HTML | DOM hasAttributes() Method
The DOM hasAttribute() method is a boolean function which 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 contains any parameter.
Return Value: It return true if the element contains attribute otherwise it returns false.
Example 1:
<!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 body element has any attributes</p> <button type = "button" onclick = "geeks()"> Submit </button> <script> function geeks() { var s = document.body.hasAttributes(); document.getElementById('gfg').innerHTML = s; } </script> <p id = "gfg"></p> </center> </body> </html> |
Output:
Before click on the Button:

After click on the Button:

Example 2:
<!DOCTYPE html> <html> <head id = "rk"> <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() { var s = document.head.hasAttributes(); document.getElementById('gfg').innerHTML = s; } </script> <p id = "gfg"></p> </center> </body> </html> |
Output:
Before click on the Button:

After click on the Button:

Supported Browsers: The browser supported by DOM hasAttributes() method are listed below:
- Google Chrome
- Internet Explorer 9.0
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM contains() Method
- HTML | DOM createElement() Method
- HTML | DOM Select add Method
- HTML | DOM removeAttributeNode() Method
- HTML | DOM hasChildNodes() Method
- HTML | DOM scrollIntoView() Method
- HTML | DOM removeChild() Method
- HTML | DOM importNode() Method
- HTML | DOM writeln() Method
- HTML | DOM normalizeDocument() Method
- HTML | DOM createTextNode() Method
- HTML | DOM click() Method
- HTML | DOM exitFullscreen() Method
- HTML | DOM cloneNode() Method
- HTML | DOM getAttributeNode() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

