Reputation: 27
I'm trying to change a CSS background image using jQuery, and the code I am using just reloads the current image. When you click the li#menu-item-23, I want the div with the class of #changeMe to switch background images
$('li#menu-item-23').click(function(){
$('#changeMe').css('background-image','url(i/logo4.png)');
});
Upvotes: 0
Views: 82
Reputation: 6411
Try this
$('#changeMe').css('background-image', 'url("i/logo4.png")');
You need to add double quotes inside url()
Also make sure you image path is correct...
Here is a brief description of the file paths:
./
means the current directory
../
means the parent of the current directory, not the root directory
/
is the root directory
myfile.text
is in the current directory, as is ./myfile.text
../myfile.text
is one level above you and /myfile.text
lives in your root directory.
Upvotes: 4