Barba Barba - 6 months ago 8
HTML Question

Changing backgroud image css

I have this simple code trying to change background image of a div. It doesn't work.

<div id="lyt_photo_1" style="position:absolute; top:19mm; left:4mm; background-color:#999999; width:21mm; height:27mm;"></div>
<script>$('#lyt_photo_1').css("background-image", "url(/Jellyfish.jpg)");</script>


Please help

Answer

Checkout this Demo It works , That means your image directory path (/Jellyfish.jpg) is wrong

<div id="lyt_photo_1" style="position:absolute; top:19mm;
 left:4mm;  width:21mm; height:27mm;"></div>

$('#lyt_photo_1').css("background-image", "url(http://lh4.ggpht.com/_X6JnoL0U4BY/S-AGp
sMhh4I/AAAAAAAAc2I/PhQJvcAMLgI
/tmp18723_thumb_thumb_thumb.jpg?imgmax=800)");