Element hasAttributes Method - Javascript DOM

Javascript examples for DOM:Element hasAttributes

Description

The hasAttributes() method returns true if it has any attributes, otherwise false.

If the node is not an Element node, the return value is false.

Parameters

None

Return Value:

A Boolean, returns true if the node has attributes, otherwise false

The following code shows how to Find out if the <body> element has any attributes:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w w w .  java 2 s  . c o  m*/
    var x = document.body.hasAttributes();
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials