Find out if the <body> element has any attributes:
var x = document.body.hasAttributes()
Click the button to find out if the body element has any attributes.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . jav a 2 s . c o m var x = document.body.hasAttributes(); document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The hasAttributes()
method returns true if the specified node has any attributes, otherwise false.
If the specified node is not an Element node, the return value is always false.
hasAttribute();