Search code examples
javascriptimageload

How can I load all images in a folder?


var img = new Image();
img.src = "images/myFolder/myImage.png";

The above will only load myImage.png. How to load all images of myFolder?


Solution

  • JavaScript can't directly access the contents of a file system. You'll have to pass the contents using a server-side script (written in PHP, etc) first.

    Then once you have that, you can use a loop in your JavaScript to load them individually.