How to add background images dynamically

6 1 2

Hi there! Is there a way to add a background image to a div dynamically using javascript? Right now I'm accomplishing this by setting up ID's in CSS with the specified background image and adding those ID's to div's using JS. But I was wondering if there was a way to cut out the CSS approach/middle man?



Shopify Expert
2577 41 602

Sure there is. You may wish to check the .css() function 

but generally it's something like

$el.css( 'background-image', 'url(' );
Want to hire me to tweak a theme? Mail me at! My post solved your problem? This is my Paypal too :)