disable and enable "buttons" of the "a" tag

1

The inconvenience that I have to start must de-enable the buttons above and below, and does not perform any function, until you click on the start button and enable the buttons and perform the functions you already have , the problem is that I do not have to change the tags (a) for some tags (button) and since I already gave a click functions to each button it does not let me perform since looking for I saw that to deactivate them it is with .bind() but also performs the function that had already given in the code.

You do not have to change the label to (button).

HTML

<a class='btn-up'><span class='triangle-up'></span></a>
<a class='btn-down'><span class='triangle-down'></span></a>

JQUERY

$(".btn-up").bind("click",false);
$(".btn-down").bind("click",false);

$("#btniniciar").on("click", function(){
    $("#btniniciar").hide();
    $("#btnreiniciar").show();
    $("#masaInputID").prop("disabled",false);
    $("#masaInputID").css("color","white");
    casos(masa);
    updateM(masa);
});
/*BOTON ABAJO*/
var decreaseMasa = document.getElementsByClassName('btn-down')[0];
    decreaseMasa.onclick = function() {
        masa = Math.round(masaInput.value);
        masa = masa - 100;
        if(masa <= 100){
            masa = 100;
        }
        casos(masa);
        updateM(masa);
    };
/*BOTON ARRIBA*/
var increaseMasa = document.getElementsByClassName('btn-up')[0];
    increaseMasa.onclick = function() {
        masa = Math.round(masaInput.value);
        masa = masa + 100;
        if(masa >= 500){
            masa = 500;
        }
        casos(masa);
        updateM(masa);
    };
    
asked by Jorge Gutierrez Yañez 06.08.2018 в 22:16
source

2 answers

2

With jQuery you can do it without the need to change the tags or their attributes:

// Una varible que por defecto esta en false
var activos = false;

$("a").click(function (e) {
    // Si los la variable es false, evita que 'a' se ejecute normalmente
    if(!activos){
        e.preventDefault();
    }
});

When you need to activate the buttons, you simply set the variable to true and the buttons will work normally

activos = true;
    
answered by 07.08.2018 / 08:29
source
0

something like this

function btn1(){
        alert("btn1");
	$("#b2").removeClass("disabled");
	$("#b1").addClass("disabled");
}
function btn2(){
	alert("btn2");
	$("#b1").removeClass("disabled");
	$("#b2").addClass("disabled");
}
    
answered by 07.08.2018 в 01:12