Skip to content

Instantly share code, notes, and snippets.

@hattmarris
Created March 22, 2017 14:09
Show Gist options
  • Save hattmarris/49a86f74466c6b0ea431a20fb5e99905 to your computer and use it in GitHub Desktop.
Save hattmarris/49a86f74466c6b0ea431a20fb5e99905 to your computer and use it in GitHub Desktop.
JavaScript - Batch Download Images
// <img>s wrapped in <a> tags
// Select images
var images = document.querySelectorAll('img');
// Get parent links
var links = [];
images.forEach(
function (el) {
links.push(el.parentElement);
}
);
// Loop and download each
links.forEach(
function(a) {
a.setAttribute('download', null); // set download attr explicitly
a.click();
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment