Disable HTML button in JavaScript

1

I want to make a function in the HTML code itself that every time we press a button a meter adds up to six and when it reaches the limit (6). Leave the button disabled. Any help?

This is the button:

<button type="button" onclick="random()">Lanzar dado !!!</button>
    
asked by Eduardo 10.10.2017 в 18:12
source

1 answer

3

Well really what you should do with your counter and the button is the following:

var contador = 0;

function random(elemento){
    if(contador >= 5){
        elemento.setAttribute('disabled', 'disabled');
    }else{
        contador++
    }
}
<button type="button" onclick="random(this)">Lanzar dado !!!</button>

I hope you serve, greetings!

    
answered by 10.10.2017 / 18:26
source