Reputation: 1803
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
Reputation: 236022
Array.prototype.forEach.call( document.images, function( img ) {
// ecmascript5 plz (but we accept a shim also)
});
Upvotes: 10
Reputation: 47776
jQuery:
$("img").each(function() {
console.log($(this).prop("src"));
});
Logs every image's src
in the console.
Upvotes: 5