Input Button name Property - Change the name of a button: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Input Button name Property - Change the name of a button:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="button" id="myBtn" name="myname" value="My 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 input button is: " + x);
}

function change() {//ww  w  . ja  v  a2  s.  c  o  m
    var x = document.getElementById("myBtn").name = "newButtonName";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials