How to change the text of an "Input.Button" ? In JS

Asked

Viewed 459 times

1

To change the text of a div, I do :

window.document.getElementById("CaixaPrincipal").innerHTML = Mensagem;

Now how do I change the text of a button? I tried this :

<input  id = "Botao" type="button" value="Segundo Caminho" onclick = "B()">
window.document.getElementById("Botao").innerHTML = Mensagem;

But it didn’t work :/

  • Remembering that the button looked like this: <input id = "Boot" type="button" value="Second Path" onclick = "B()">

  • You do not score your questions, have no interaction with the crowd, check out the tour of the website

1 answer

3

Face the text of your input:button is in the value then you have to change the value of value and not the text because theoretically no text has within the input rather a value

Then use .value to put a value that will appear as "text" inside the button. And the value you will declare has to be entre aspas if it is a string as is your case...

document.getElementById("Botao").value = 'Mensagem';
<input  id="Botao" type="button" value="Segundo Caminho" >
<input  id="BotaoX" type="button" value="Segundo Caminho" >

  • Thanks, it worked !

  • @Alexjuniorpereira without problems friend! If the answer helped you and you consider the problem solved remember to mark the answer as accepted by clicking on the icon below the arrows next to my answer. So your question is not open even though it has already been solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.