Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery: Adding background image to div Reply To: jQuery: Adding background image to div

#189181
Anonymous
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)'