I have html code below:
JavaScript
x
2
1
<li class="name1 name2 name3" data-animate-effect="fadeIn" style="background-image: url(images/gallery-1.jpg); ">
2
Then how to set images/gallery-1.jpg
to my imageURL
variable javascript by querySelector? This is my try and error:
JavaScript
1
2
1
let imageURL = gallery[newIndex].querySelector("li").style.background.url;
2
Advertisement
Answer
A little more code needed
You can change document.querySelector("[data-animate-effect]")
to gallery[newIndex].querySelector("li")
if preferred
JavaScript
1
2
1
console.log(document.querySelector("[data-animate-effect]")
2
.style.backgroundImage.match(/"(.*)"/)[1])
JavaScript
1
1
1
<li class="name1 name2 name3" data-animate-effect="fadeIn" style="background-image: url(images/gallery-1.jpg); ">