jack jack - 1 month ago 6
Javascript Question

How to create x amount of image box in html javascript?

So basically I've a simple project where users could upload some images. Now I need to create

x
amount
<img/>
boxes, where
x
contains the amount of photos that user have saved in my server.

I would really appreciate if somebody could tell me how to create x amount of image boxes in html.

Thanks in advance

Answer

Use jquery to create tags at runtime:

Example:

$(function(){
  var x = 10;
  for(var i=0; i<x; i++){
    $('body').append('<img src="http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons-256/firey-orange-jelly-icons-symbols-shapes/018349-firey-orange-jelly-icon-symbols-shapes-smiley-face1.png" alt="Smiley face" width="42" height="42">');
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<body>


</body>
</html>