Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  5] [ 4]  / answers: 1 / hits: 15350  / 13 Years ago, wed, march 23, 2011, 12:00:00

I'm trying to save the background-image of a element, remove it and then maybe add it back later.



var current_bg_image = $(#div).css(background-image);
if(something){
$(#div).css(background-image, none);
}else{
$(#div).css(background-image, current_bg_image); // not working...
}


The part where the background image is supposed to be added back doesn't work...
But if I change current_bg_image with url(something.jpg) it works. It seems that css() doesn't work with variables?


More From » jquery

 Answers
5

Your code works fine for me using jQuery 1.5.1. I believe what you will get once saving the background-image value to current_bg_image is the full path to the image, so try reading that value using Firebug or alert(current_bg_image) and ensure it is what you think it should be.


[#93125] Monday, March 21, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
noel

Total Points: 49
Total Questions: 90
Total Answers: 104

Location: Aland Islands
Member since Wed, Nov 17, 2021
3 Years ago
noel questions
;