To set a button’s value using JavaScript, we can set the innerHTML
property of the button.
For instance, if we have the following HTML:
<form>
<button name="submit-button">Original<br>Text</button>
</form>
We can write:
const form = document.querySelector('form')
form.elements["submit-button"].innerHTML = 'submit'
to get the form with document.querySelector
.
Then we get the button with the name
attribute set to submit-button
with:
form.elements["submit-button"]
And we set the innerHTML
property of it to 'submit'
.
Therefore, the button in the form would have ‘submit’ as its text content.