-2
I want to change the value of the button always with -1, without showing alert.
Follows code:
<button onclick="alert(this.value);this.value -= 1;" value="200">200</button>
-2
I want to change the value of the button always with -1, without showing alert.
Follows code:
<button onclick="alert(this.value);this.value -= 1;" value="200">200</button>
2
To prevent the alert from appearing, simply remove the call from alert()
.
Already to update the text button (which is not the same as the attribute value
), you should also update the property innerHTML
:
function diminuiValor(botao) {
// diminui o "value"
botao.value -= 1;
// atualiza o texto do botão para ser o mesmo que o value
botao.innerHTML = botao.value;
}
<button onclick="diminuiValor(this);" value="200">200</button>
Or, more directly (without creating a function
):
<button onclick="this.value -= 1; this.innerHTML = this.value;" value="200">200</button>
In short, this.value -= 1
decreases the value that was set in the attribute value="200"
, as long as the innerHTML
updates the button text. In the examples above I’m assuming you want to change both (because that’s what makes most sense to me).
Bro thanks! That’s what I wanted! Tmj was worth❤
0
See the example you want:
$("#id_do_botao").click(function() {
var valor = this.value -= 1;
$(this).text(valor);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="id_do_botao" value="200">200</button>
Matheus like, I want the value to decrease by clicking on the right button? So more I don’t want to keep popping this Alert I wanted the value decrease on top of the same button or down tended?
@Jdchaves my code is doing what ? Click run and test.
rsrsrs.. I guess he didn’t go with your guy.
I tested bro but it didn’t work!
@Leandrade because it is kkk
@Matheusmiranda I think you did with jQuery, then it didn’t work there for him.
Kkkk not bro none of this sorry bro I tested more didn’t work!
Thanks for the help Matheus!!❤
Browser other questions tagged javascript html5
You are not signed in. Login or sign up in order to post.
What is 200 ? Try to explain better.
– Matheus Miranda
Please elaborate your question and if possible enter the code you are using.
– Rodrigo Tognin
Do not put in the comment. Ask the question.
– Matheus Miranda
I can’t put in the question!
– JDchaves
@Jdchaves, You want to decrease the alert button ?
– Matheus Miranda
No I want to remove the alert and decrease the values without the alert appears!
– JDchaves
@Jdchaves, You want to change the value without showing alert ?
– Matheus Miranda
That’s right Matheus!
– JDchaves
@Jdchaves looks at my answer.
– Matheus Miranda
Okay I’ll check here!
– JDchaves