Changing background image using jquery

getaway picture getaway · Jan 2, 2011 · Viewed 61.9k times · Source

I have this jquery code that changes the image of the background on click:

$('a.note').click(function(){
  $('#full').css('background-image','img/1.jpg');

});

However, it's not changing. Is there something I'm missing?

Answer

user113716 picture user113716 · Jan 2, 2011

You need to include the url() part of the background-image property.

$('#full').css('background-image','url(img/1.jpg)');