Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
How to add and remove class using ajax based on cart count

My cart is incremented using an ajax call. I want to add a class when the counter is 1 and remove a class when the counter is 0. Can someone tell me how can I achieve this without a page load? Is there any ajax query which fires automatically when the counter increments and decrements? https://prnt.sc/1xaim0a
https://prnt.sc/1xaipj8

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

$(document).on("click", function () {
  var count_new = 0;
  var subtotal_new = 0;
  setTimeout(function () {
    jQuery.getJSON('/cart.js', function (data) {
      count_new = data.item_count;
      if (parseInt(count_new) == 0) {      
        $(".Cart_click").find(".mobile-icons").find(".hotiya").removeClass("cart_ping")
      } else {
        $(".Cart_click").find(".mobile-icons").find(".hotiya").addClass("cart_ping")
      }
    });
  }, 500);
});

I devised a solution.

about 4 years ago · Juan Pablo Isaza Report

0

Why not check, after the ajax call, the value of counter and update according that the class? This is an exemple of ajax callback:

function (data) {
    if(data.counter == 0){
         $('#id').removeClass('the-class');
    }else{
         $('#id').addClass('the-class');
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!