Good day to all! Help solve the problem) There is a piece of code

<a href="/cart/" class="cart">Корзина: <span class="cart-empty">0</span> шт. На сумму: 0 руб.</a> 

Code cart empty

 <a href="/cart/" class="cart">Корзина: <span class="cart-empty">2</span> шт. На сумму: 2000 руб.</a> 

basket code full

Above, if the basket is not empty, assign additional. class class = "cart".

Thank you in advance!

  • Do it initially with this class, then in the code for adding goods to the basket - change the class as well. I understand the addition of goods is using ajax? - Moonvvell
  • yes, ajax. I thought to do something like checking on JS. if there are 0 items in the cart, adding a class - Andrey Vasilyev

1 answer 1

 $(document).ready(function(){ if($('.cart-empty').text() > 0) { $('.cart').toggleClass('full'); } }) 
 .full { background:red; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="/cart/" class="cart">Корзина: <span class="cart-empty">2</span> шт. На сумму: 2000 руб.</a> 

  • What you need! Thank you very much!!! Need to learn JS))) - Andrey Vasilyev