tags:

views:

44

answers:

2

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

+2  A: 

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'});
      }); 
 }
dhanke
However, the way you choose is not be best one. better toggle a class, just like NimChimpsky tells you to in his comment. makes it more clear + adds support for changing themes etc.
dhanke
+1  A: 

you could "toggle" a class ...

NimChimpsky
like you mean to say change the class name according to the if condition
prakash
toggle a class will assign a class if its not there, and remove it if it is, so no need to use if. Put all your css and file reference in the class definition.
NimChimpsky