Get the name of a <button> element's second (index 1) attribute:
var x = document.getElementById("myBtn").attributes[1].name;
Click the button to display the name of the button's second attribute (index 1).
<!DOCTYPE html> <html> <body> <button id="myBtn" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w ww . j a v a 2s. c o m*/ var x = document.getElementById("myBtn").attributes[1].name; document.getElementById("demo").innerHTML = x; } </script> </body> </html>