1
I have a button that at the click of it directs to a request in ajax to an external file that adds a product, however this does not matter much in this case. I wanted to manipulate what is written in span
button. Every time the user clicked on buy, it would change to remove. And, the reverse would happen too, every time the user clicked the remove button, the span
of that button would change to buy. What I managed to do was that the span
of the button clicked change to remove, but the reverse has 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>
Code of the Ajax request:
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);
}
});
}
Do you want to change only the text? And the button function?
– Sam
Yeah, that’s right.
– Matheus Portela