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?
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.
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.
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.
You need to include the url()
part of the background-image
property.
$('#full').css('background-image','url(img/1.jpg)');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With