flea whale
flea whale

Reputation: 1803

Loop through every IMG in current document

I'm making a Chrome extension and am wondering, what is the best method for looping through each IMG object on the current document using only JS/jQuery?

Upvotes: 1

Views: 4877

Answers (2)

jAndy
jAndy

Reputation: 236022

Array.prototype.forEach.call( document.images, function( img ) {
    // ecmascript5 plz (but we accept a shim also)
});

Upvotes: 10

Alex Turpin
Alex Turpin

Reputation: 47776

jQuery:

$("img").each(function() {
    console.log($(this).prop("src"));
});

Logs every image's src in the console.

Upvotes: 5

Related Questions