jquery - Javascript gallery, adding images with "for" loop -


i'm creating gallery in project, don't want spam clear html , repeat 20 times in code. want create loop in javascript numbers of images folder , later add 1 div. i've created code don't know how step it. code:

function addingimages() {      (var = 0; <= ***; i++) {         var image = document.createelement("img");         image.setattribute("src", "images/1.jpg");         document.queryselector(".gallery").appendchild(image);     } } 

*** - don't know should there. , know need variable increment later numbers of images 1.jpg , 2.jpg, 3.jpg etc.

you need loop 1 20, set loop count 20. use index loop in setattribute function this:

   function addingimages() {     (var = 1; <= 20; i++) {         var image = document.createelement("img");         image.setattribute("src", "images/" + + ".jpg");         document.queryselector(".gallery").appendchild(image);    } } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -