Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  56] [ 2]  / answers: 1 / hits: 21875  / 11 Years ago, sun, october 13, 2013, 12:00:00

I wrote this code part in my JavaScript file to select all img tags in my .html file.



var imgs = document.getElementsByTagName('img');


How can I extract the src values of those tags to an array for future use?


More From » html

 Answers
17

Just try like this



function img_find() {
var imgs = document.getElementsByTagName(img);
var imgSrcs = [];

for (var i = 0; i < imgs.length; i++) {
imgSrcs.push(imgs[i].src);
}

return imgSrcs;
}

[#75025] Friday, October 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sandra

Total Points: 708
Total Questions: 100
Total Answers: 84

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
sandra questions
Tue, Jun 30, 20, 00:00, 4 Years ago
Sun, May 31, 20, 00:00, 4 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Fri, May 31, 19, 00:00, 5 Years ago
;