prakash
prakash

Reputation: 21

Jquery if statement for background-image css value

i am trying to compare the value of background-image and do image that image to another one here is the snippet

if ($('.list').css("background-image") === "url(images/Remove.png"){
   $('.list').click(function(){
      $('.list').css({
         'padding-left'      : '40px',
         'background-image'  : 'url(images/Remove_vertical.png)',
         'background-repeat' : 'no-repeat'
      });
   }
}

This is not working any suggestion

Upvotes: 2

Views: 4629

Answers (2)

NimChimpsky
NimChimpsky

Reputation: 47290

you could "toggle" a class ...

Upvotes: 1

thedanielhanke
thedanielhanke

Reputation: 738

Your syntax is wrong.

if ($('.list').css("background-image") === "url(images/Remove.png"){  

e.g. should look like

if ($('.list').css("background-image") === "url(images/Remove.png)") {  

instead.


 if ( $('.list').css("background-image") === "url(images/Remove.png)" )
 { 
      $('.list').click(function()
      { 
           $('.list').css({'padding-left' : '40px' , 
                    'background-image' : 'url(images/Remove_vertical.png)', 
                    'background-repeat' : 'no-repeat'});
      }); 
 }

Upvotes: 4

Related Questions