How to add background images dynamically

Tourist
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?

 

 

0 Likes
Highlighted
Shopify Partner
2536 31 562

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

but generally it's something like

$el.css( 'background-image', 'url(https://domain.org/image.jpg)' );
Want to hire me to tweak a theme? Mail me at tairli@yahoo.com! My post solved your problem? This is my Paypal too :)
0 Likes