Ali
Ali

Reputation: 267077

How to change background-image css property w/jquery

How can I set the background-image css property of say a div using jquery? will something like this work?

$("#div").css("backgroundImage", "url('test.jpg')");

Upvotes: 0

Views: 368

Answers (1)

Nick Craver
Nick Craver

Reputation: 630409

What you have will work, or you can do this:

$("#div").css("background-image", "url('test.jpg')");

Or .css() takes an object (to set many properties for example):

$("#div").css({ backgroundImage: "url('test.jpg')", color: "red" });

Upvotes: 3

Related Questions