javascript change button text onclick code example
Example 1: javascript change button text onclick
<!DOCTYPE html>
<html>
<body>
<button id="demo" onclick="myFunction()">Click me to change my HTML content (innerHTML).</button>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed!";
}
</script>
</body>
</html>
Example 2: js change button text
<button id="buttonName">Old Text</button>
<script>document.getElementById('buttonName').innerText = 'New Text';</script>
Example 3: how to change the text in a button on onclick
var btn = document.getElementById("mybtn");
btn.value = 'my value'; // will just add a hidden value
btn.innerHTML = 'my text';
Example 4: change button text by id click java
<input type="button" value="Button Text" id="myButton1"></input>