Rhys Edwards Rhys Edwards - 3 months ago 14
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.

$(document).ready(function(){
$("button").click(function(){
$("content1").css("background-image", "url(../images/light.png)");
});
});

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


My css is external.

Thankyou.

Ish Ish
Answer

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

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