+ 1

How to set background image using javascript?

13th Jun 2016, 3:19 PM
sreeraj thampan
sreeraj thampan - avatar
2 Answers
+ 3
you can create function in your script code and then create variable. for the variable you can use document.getelementbyid(/your parameter/).style.background-image = url('/your image/'); just check on this site http://stackoverflow.com/questions/18665702/javascript-setting-background-image-of-a-div-via-a-function-and-function-paramet
13th Jun 2016, 3:54 PM
Firda Dhea Sauzan
Firda Dhea Sauzan - avatar
+ 2
<div id="div_id"></div> <script type="text/javascript"> var bg = document.getElementById('div_id').style.background-image = url(' images/test.png'); </script>
13th Jun 2016, 9:26 PM
xgqfrms
xgqfrms - avatar