[Solved] Get url image with javascript?


You could use getElementById in case you have multipe nested images in different id’s.
Then you could use getElementsByTagName to get the image elements and loop those using a for loop and storing the src in an array urls.

var elms = document.getElementById('content').getElementsByTagName('img');
var urls = [];
for (var i = 0; i < elms.length; i++) {
    urls.push(elms[i].src);
}
console.log(urls);
<article id="content">
    <img src="https://stackoverflow.com/questions/47483408/anh-1.jpg">
    <img src="../anh-2.jpg">
    <img src="../anh-3.jpg">
</article>
<article id="content2">
    <img src="../anh-4.jpg">
    <img src="../anh-5.jpg">
    <img src="../anh-6.jpg">
</article>

solved Get url image with javascript?