Javascript examples for DOM HTML Element:Button
Button name Property - Change the value of the name attribute of a button:
<!DOCTYPE html> <html> <body> <button id="myBtn" name="myname">My Button</button> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> function display() { var x = document.getElementById("myBtn").name; console.log("The name of the button is: " + x); } function change() {//from w w w .j a va 2 s. c o m var x = document.getElementById("myBtn").name = "newButtonName"; console.log("The name was changed to: " + x); } </script> </body> </html>