Problem in function

1

Good afternoon GRAN community. I have a problem in a function that goes to 90%. The problem is in the BeforeSend of the code, when I delete an item from the cart, a spinner is activated, but it is activated in all the elements, and I want it to only be activated in the element that I want to eliminate. The code is as follows:

$(document).on("click", ".removecartitem", function(){
    var $t = $(this);
    var rurl = $t.attr("data-remove-url");
    var delrowid = $t.attr("datarowid");
    var qty = $t.attr("dataitemqty");
    var spn = $(".remover-spinner") ;
    $.ajax({
        type: "POST",
        url: rurl,
        beforeSend: function(data){

            spn.fadeIn(100)


   },
        success: function(data) {
            $('.'+delrowid).fadeOut(200, function(){
                spn.fadeOut(100)
                $('.'+delrowid).remove(); carttotalamount();

            }); 
        }
    });
});



<p class="remove_link">
                            <!-- a rel="nofollow" class="removecartitem" href="javascript:;" datarowid="removerowitem{$products.id}" dataitemqty="{$products.quantity}" data-remove-url="{$products.remove_from_cart_url}"> -->

                    <a rel="nofollow" class="removecartitem" href="javascript:;" datarowid="removerowitem{$products.id}" dataitemqty="{$products.quantity}" data-remove-url="{$products.remove_from_cart_url}">
                            <span class="remove-cartsection"><i class="material-icons" id="remover-product">delete_forever</i></span>
                            <span class="remover-spinner"></span>
                    </a>
</p>

Thank you very much for your extreme collaboration!

    
asked by Andres Matias 26.09.2018 в 20:21
source

1 answer

2

The selector you have chooses all the spinners. You must change it like this:

$(document).on("click", ".removecartitem", function(){
    var $t = $(this);
    var rurl = $t.attr("data-remove-url");
    var delrowid = $t.attr("datarowid");
    var qty = $t.attr("dataitemqty");
    var spn = $(this).find(".remover-spinner") ;
    $.ajax({
        type: "POST",
        url: rurl,
        beforeSend: function(data){

            spn.fadeIn(100)    

   },
        success: function(data) {
            $('.'+delrowid).fadeOut(200, function(){
                spn.fadeOut(100)
                $('.'+delrowid).remove(); carttotalamount();

            }); 
        }
    });
});
    
answered by 26.09.2018 / 20:47
source