Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="class1" style="background-image:url(https://www.awebsite.com/sites/default/files/a_image.jpg?t=1529620960)"></div>
- https://www.awebsite.com/sites/default/files/a_image.jpg?t=1529620960`
- https://hello.com/an-other-image.jpg
- c = document.getElementsByClassName('class1');
- for(i = 0; i < c.length; i++){
- c[i].style.backgroundImage = 'url(https://hello.com/an-other-image.jpg)';
- }
- // querySelector can use CSS selectors to find the element in the document
- // note: this is assuming there is only 1 element on page with this class
- var myDiv = document.querySelector('.class1');
- // Style properties generally match CSS but camel cased
- myDiv.style.backgroundImage = 'url("https://hello.com/an-other-image.jpg");
Add Comment
Please, Sign In to add comment