Home › Forums › JavaScript › jQuery: Adding background image to div › Reply To: jQuery: Adding background image to div
November 25, 2014 at 9:43 am
#189181
Inactive
This is not server-based.
The user enters the image path in an input field for example “img/mountain.jpg”.
That image path is added like this
var imgPath = $("input").val();
$("div").css("background-image","url("+ imgPath +")";
<code></code>
Instead of it looking like this
background-image: url(img/mountain.jpg);
It looks like this
'background-image: url(http://localhost/img/mountain.jpg)'