Rhys Edwards Rhys Edwards - 1 year ago 84
CSS Question

Change background image with a button w/ jQuery

I want to change the background image on the div "content1" when i click on a button.

$("content1").css("background-image", "url(../images/light.png)");

.content1 {
background-image: url('../images/dark.png');

My css is external.


Ish Ish
Answer Source

Your content is a class. so you need to use jquery selected properly.

 $(".content1").css("background-image", "url(../images/light.png)"); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download