Change the value of the name attribute of a button:
document.getElementById("myBtn").name = "newButtonName";
Click the buttons below to display and change the value of the name attribute of the button.
<!DOCTYPE html> <html> <body> <button id="myBtn" name="myname">My Button</button> <p id="demo"></p> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> function display() { var x = document.getElementById("myBtn").name; document.getElementById("demo").innerHTML = "The name of the button is: " + x; } function change() {/* w w w . jav a2s. c o m*/ var x = document.getElementById("myBtn").name = "newButtonName"; document.getElementById("demo").innerHTML = "The name was changed to: " + x; } </script> </body> </html>