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?
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_imageis the full path to the image, so try reading that value using Firebug oralert(current_bg_image)and ensure it is what you think it should be.