What would be the best way to get the IMG SRC to an array such as:
var images = [ ‘img1.png’, ‘img2.png’, img3.png’ ];
<div class="cc">
<img class='content-image' src="./img1.png" alt="">
<img class='content-image' src="./img2.png" alt="">
<img class='content-image' src="./img3.png" alt="">
<img class='content-image' src="./img4.png" alt="">
<img class='content-image' src="./img5.png" alt="">
</div>
Have tried this:
var images = []; const interactImg2 = document.querySelector('.cc'); [...interactImg2.querySelectorAll('img[src]')].forEach(img => images.push(new Image('img[src]')));
Unable to get the SRC but the item shows as ( Image1, Image2, Image3 )
>Solution :
var images = [];
const interactImg2 = document.querySelector(".cc");
[...interactImg2.querySelectorAll("img[src]")].forEach((img) =>
images.push(img.getAttribute('src'))
);
Try this code. If you have any problem further, feel free to reach out me.