2021年3月11日星期四

How To Grab Image Source From CSS Background Image

This is my first question ever, please show some love!

I'm trying to grab the background image from a div element and append it to a div every time I push a bottom. Below is the mockup code:

<div class="img"></div>    .img {  background: url("local image file");  }    function addImage(imageSrc) {    var imageSrc = document.getElementByClassName('img')[0].getComputedStyle.background  }  

I could not find a way to grab the local path inside the background url(""). Can someone please help? I only know vanilla Javascript.

Thank you!

https://stackoverflow.com/questions/66593557/how-to-grab-image-source-from-css-background-image March 12, 2021 at 10:59AM

没有评论:

发表评论