Geeth Welagedara Geeth Welagedara - 1 year ago 88
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>




Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download