I want to add a class to #cart-total-remove with the location fonction i tried many ways but didn't work

Viewed 102

this is the cart success function

success: function(json) {
                // Need to set timeout otherwise it wont update the total
                setTimeout(function () {
                    $('#cart > button').html('<span id="cart-total-remove"><img src="http://localhost/nerv/image/catalog/icons/bag.png"/> ' + json['total'] + '</span>');
                }, 100);

                if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
                    location = 'index.php?route=checkout/cart';
                } else {
                    $('#cart > ul').load('index.php?route=common/cart/info ul li');
                }
            },

and i tried to add the class change-remove to style it later

$(document).ready(function() {
    
    if ( window.location.href == 'http://localhost/nerv/index.php?route=common/home' ){
        $("#cart #cart-total-remove img").removeClass("change-remove");
    } else {
        $("#cart #cart-total-remove img").addClass("change-remove");
        console.log(window.location.href);
    }

});

this is my css codes

#cart #cart-total-remove img {
    filter: invert(1);
}
#cart #cart-total-remove img.change-remove{
    filter: none;
}

Any help would be appreciated

2 Answers

Try this if it might Help.

Your CSS code has the class img.change-remove and the class you are trying to add was .change-remove, thus it(your css) has to be:

Notice the change in the css code of img .change-remove not img.change-remove

#cart #cart-total-remove img {
filter: invert(1);
}
#cart #cart-total-remove img .change-remove{
filter: none;
}

here check your both conditions work or not

$(document).ready(function() {
    
    if ( window.location.href == 'http://localhost/nerv/index.php?route=common/home' ){
        $("#cart-total-remove img").removeClass("change-remove");
    } else {
        $("#cart-total-remove img").addClass("change-remove");
        console.log(window.location.href);
    }

});
Related