I have some buttons that in the click of the same directs an ajax request to an external file that adds a product, however this does not matter much in this case. I manipulate these buttons, and every time the button with span
buy, where in the click of the same, span
is changed to remove and when the remove button is clicked the span
is changed again to buy. I need every time that the buy button is clicked, all of them are disabled for the click minus the button that has span
remove, so that it is clicked, span
is changed to buy and that the other buttons can now be clicked again.
Button code:
<button type="button" class="button btn-cart" onclick="addCartao('<?php echo $_product->getId(); ?>')" name="cartaoMensagem<?php echo $_product->getId(); ?>" id="cartaoMensagem"><span><span>Comprar</span></span></button>
Ajax request code:
function addCartao(product_id){
$j.ajax({
type: "POST",
url: "teste.php",
data: {
product_id: product_id
},
dataType: 'json',
cache : false,
beforeSend: function () {
},
success: function (retorno) {
var button = $j('button[name=cartaoMensagem' + product_id + ']');
if($j(button).text() == '<span><span>Comprar</span></span>'){
$j('#cartao').find(':button').attr('disabled',true);
$j(button).html('<span>Remover</span>');
}else{
$j(button).html('<span>Comprar</span>');
}
},
complete: function () {
},
error: function (x,y,z) {
alert("error");
alert(x);
alert(y);
alert(z);
}
});
}
Note: The code I made disabled all the buttons inside the card div, which are the ones that are in the question, but how they are disabled, at the click of the button that has span
remove , it does not do any kind of action.