Javascript examples for DOM:Attribute
The length property returns the number of nodes in a NamedNodeMap object.
This property is read-only.
A Number, representing the number of attribute nodes in the nodemap
The following code shows how to get the number of attributes of a <button> element:
<!DOCTYPE html> <html> <head> <style> .example {/*from www. jav a2 s . c om*/ color: red; padding: 5px; width: 150px; font-size: 15px; } </style> </head> <body> <button id="myBtn" onclick="myFunction()" class="example">Test</button> <p id="demo"></p> <script> function myFunction() { var txt = ""; var x = document.getElementById("myBtn").attributes; var i; for (i = 0; i < x.length; i++) { txt += "Attribute name: " + x[i].name + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>