JQUERY HELP NEEDED IN CHANGING COLOR IN CONDITION

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
JQuery 
 1157  View(s)
Ratings:
Rate this:
Hi Expert!

I want a jQuery snippet for changing color of a button on condition--> I am using woocommerce with WordPress. What I want is : if there is Cart item is 0 then I want 

to show red color and if any item in cart then the button goes green

Please Help!

Thanks In Advance
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Jquery Help needed in changing color in condition

    Hi Takeshi!


    Put your item number in a div/span and give an id. For example I took 'item_container' is the id of that div then:

    $(document).ready(function(){
       var item_nu = $('#item_container').html().parseInt();
        if(item_nu=='0')
         {
           //write your code here to make the button red
         }
        else{
           //write your code here to make the button green
         }
     })

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!