Geeth Welagedara Geeth Welagedara - 2 months ago 18
Javascript Question

How to load all the images from one Directory

i tried to display all images in one directory using following

. But it is not working. My folder structure is just a images folder and
I just followed this question also, but couldnt achive the target.

enter image description here

< script >
$(document).ready(function() {

var folder = "images/";
url: folder,
success: function(data) {
$(data).find("a").attr("href", function(i, val) {
if (val.match(/\.(jpe?g|png|gif)$/)) {
$("body").append("<img src='" + folder + val + "'>");
}); < /script>

<!DOCTYPE html>

<script src="js/jquery.min.js"></script>





First of all you need to create a server page which will provide you list of names from that directory. you need to call that page (instead of folder name) from your $.ajax function.

Second, loop over that list of image names (paths) and create image elements. You are doing the similar stuff.