Created
September 3, 2021 01:17
-
-
Save warnakey/09b2867b19c9ce53d5ebe869c9ef8326 to your computer and use it in GitHub Desktop.
Remove GIFs from a collection of images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Let's say you have a series of images, and some are JPGs or PNGs, but some are GIFs too. If you want to remove the GIFs, you can do this. | |
Let's assume your HTML looked like this: | |
<div> | |
<img src="https://sqairz.com/wp-content/uploads/2021/04/freedom-white-silver-gif-600x394.gif"> | |
<img src="https://sqairz.com/wp-content/uploads/2021/04/Sqairz-Shoes_071-600x600.jpg"> | |
<img src="https://sqairz.com/wp-content/uploads/2021/04/freedom-white-silver-gif-600x394.gif"> | |
</div> | |
*/ | |
var getAllImages = document.getElementsByTagName('img'); | |
for (var i = 0; i < getAllImages.length; i++) { | |
(function(x) { | |
var theimage = getAllImages[x]; | |
var thesrcs = getAllImages[x].getAttribute('src'); | |
const substring = "gif"; | |
if (thesrcs.includes(substring)) { | |
theimage.remove(); | |
} | |
}(i)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment