1
I have several buttons where at the click of it directs to an Ajax request passing as parameter the id of a product and through an external file, according to it is added to the cart but this is not so relevant. Another thing not so important in this case is that when this button is clicked its text is changed from "Buy" to "Remove" and vice versa. In the success of this request, I get the return that the external file brings me(an array) and "mount" it to be displayed on the page HTML
. I was wondering how I could remove this .append
what I do.
Obs: the HTML
is mounted in a class called .item-custom
where the page loading is already filled with other things and if I use the code $j('.item-custom').remove();
all that is within this class is removed, but I only wish to remove the .append()
what I do.
Button code:
<button type="button" class="button btn-cart" onclick="addCartao('<?php echo $_product->getId(); ?>')" name="cartaoMensagem<?php echo $_product->getId(); ?>"><span><span>Comprar</span></span></button>
Code of the Ajax request:
function addCartao(product_id){
$j.ajax({
type: "POST",
url: "adicionar.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() == 'Comprar'){
$j('#cartao').find(':button').not(button).attr('disabled',true);
$j(button).html('<span>Remover</span>');
$j('.item-custom').append('<tr><td class="a-center lc-thumbnails"><img src="' + retorno['imagem'] + '" width="50" height="50" alt="' + retorno['name'] + '"></td><td><h3 class="product-name">' + retorno['name'] + '</h3></td><td class="a-center">1</td><td class="a-right"><span class="cart-price"><span class="price"> R$ ' + retorno['price'] + '</span></span></td></tr>');
} else{
$j('#cartao').find(':button').attr('disabled',false);
$j(button).html('<span>Comprar</span>');
}
},
complete: function () {
},
error: function (x,y,z) {
alert("error");
alert(x);
alert(y);
alert(z);
window.location.reload();
history.go(0);
window.location.href=window.location.href;
}
});
}
On that new line you add there is no button to remove? Do you want to remove by clicking on the same button that created the new line but now says
Remover
right?– Sergio
Dude, I’m not sure I understand. vc wants to remove only = '<tr><td class="a-center Lc-thumbnails"><img src="' + return['image'] + 'width="50" height="50" alt="' + return['name'] + '"></td><td><H3 class="product-name">' + return['name'] + '</H3></td><td class="a-center">1</td><td><class="a-right"><span="Cart-price"><span class="price"> R$ ' + return['price'] + '</span></span></td></tr>' ?
– alan
@Sergio Certo, that’s right.
– Matheus Portela
@Alan Yes, wanted to remove just this.
– Matheus Portela
if your class = "Lc-thumbnails" is unique you can do it $('.Lc-thumbnails'). parents('tr'). remove(); or $('.Lc-thumbnails'). Parent(). remove();
– alan