Languages
[Edit]
EN

JavaScript - get all png images from web page

0 points
Created by:
Jan-Alfaro
681

In this article, we would like to show you how to get all .png images from web page using JavaScript.

Quick solution:

Note:

In both cases the code needs to be executed after window load event or at the end of the script to make sure that all elements are loaded before the function execution.

 

Practical example

Edit

In this example, we create function that uses querySelectorAll() method with 'img[src$=".png"]' selector to get all the <img> elements with .png extension from the web page. Then we call the function on window load event.

Note:

As you can see, the method gets only images with .png extension, omitting other images.

 

References

Edit
  1. Document.querySelectorAll() - Web APIs | MDN
  2. Window: load event - Web APIs | MDN
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join