Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Attributes to array

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading