I have a button that in the click of the same directs an ajax request to an external file that adds a product, however that does not matter much in this case. I wanted to manipulate what is written in the span
of button. Every time the user clicked buy, it would change to remove. And, the reverse would also happen, every time the user clicks the remove button, the span
of that button would change to buy. What I was able to do was that the span
of the button clicked changed to remove, but the reverse did not yet.
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) {
$j('button[name=cartaoMensagem' + product_id + ']').html('Remover'); //Código que consegui fazer
},
complete: function() {
},
error: function(x, y, z) {
alert("error");
alert(x);
alert(y);
alert(z);
}
});
}