The length
property returns the number of nodes in a collection.
length |
Yes | Yes | Yes | Yes | Yes |
obj.length;
A Number representing the number of nodes in the nodemap.
The following code shows how to get the number of attributes of a button element.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--from www . ja v a2 s. co m-->
<p id="demo"></p>
<script>
function myFunction() {
var a = document.getElementsByTagName("BUTTON")[0].attributes;
var x = document.getElementById("demo");
x.innerHTML = a.length;
}
</script>
</body>
</html>
The code above is rendered as follows: