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

1
  • There's a missing parenthesis in what you pasted here: url(images/Remove.png" - what does not work? Commented Sep 13, 2010 at 13:01

2 Answers 2

4

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'});
      }); 
 }
Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

you could "toggle" a class ...

2 Comments

like you mean to say change the class name according to the if condition
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.