Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing background image using jquery

Tags:

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?

like image 602
getaway Avatar asked Jan 02 '11 14:01

getaway


People also ask

How to replace background image in jQuery?

To change the background image using jQuery, you can use the jQuery CSS() method. For this, the whole property value is specified using the url() functional notation. Approach: Suppose we have an image URL stored in a variable and then use css() method to change the value of background image.

How to get background image in jQuery?

The task is to get a div's background image with jQuery. You can achieve this task by using the CSS() method in jQuery. In simple words, we need to create an empty div and on click event, the empty div will get the image as a background.

How can set background color in jQuery?

To set the background color using jQuery, use the jQuery css() property. We will set background color on mouse hover with the jQuery on() method.


1 Answers

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

$('#full').css('background-image','url(img/1.jpg)'); 
like image 162
user113716 Avatar answered Oct 01 '22 11:10

user113716