Let’s say I have #button with a given background-image:url(images/some_background) and I want to change it to another background when I click it, let’s say url(images/other_background).
HTML
<a id="button" ></a>
CSS
display: block;
height:100px;
width:100px;
background-image:url(images/other_background.png)
I tried this, but it doesnt work :
$(document).ready(function(){
$('#button').click(function(){
$('#button').css('backgroundImage', 'url(images/other_background.png)');
});
});
This works for me
CSS
border to see easier only
code
http://jsfiddle.net/jasongennaro/Lvnmw/
Obviously, you will need to switch out the images for your own.
If you are having trouble, check
That you are calling the jQuery script first, before this script.
That the path to your images is correct.