24

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?

staticbeast
  • 2,073
  • 2
  • 22
  • 24
getaway
  • 8,792
  • 22
  • 64
  • 94
  • possible duplicate of [Setting background-image using jQuery CSS property](http://stackoverflow.com/questions/512054/setting-background-image-using-jquery-css-property) – Cees Timmerman Jul 06 '14 at 00:58

1 Answers1

46

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

$('#full').css('background-image','url(img/1.jpg)');
user113716
  • 318,772
  • 63
  • 451
  • 440
  • how do i remove it the backround image on click function!!! thanks :)) +upvote from me – getaway Jan 02 '11 at 14:18
  • 2
    @getaway: Set it to an empty string. `.css('background-image','');` – user113716 Jan 02 '11 at 14:19
  • thanks you very much, i will accept the answer when it lets me lol!! – getaway Jan 02 '11 at 14:21
  • 3
    @getaway: Come to think of it, a more appropriate way to remove the image is probably to set it to "none" `.css('background-image','none');` since that is the correct value for no background image. http://www.css3.com/css-background-image/ – user113716 Jan 02 '11 at 14:31
  • I would also like to note that there should be NO space between "url" and "(". That was driving me nuts for a couple of hours. – Rorchackh Jul 11 '12 at 09:47