Home > Mobile >  the image is not showing up
the image is not showing up

Time:10-26

the images in the directory "training_images/class1" are frame 0 to 99

for (var i = 0; i < 100;   i){                         
   $("#class1-images").prepend($('<img>',{id:'theImg',src:'training_images/class1/frame'   i   ".jpg"})                             
)}

so when i run this code i do not see the images

i need the images to be displayed i tried dragging the image into google chrome and copied the path from there and pasted the url in my code but its still not working

CodePudding user response:

You are trying to select a tag <img> which doesn't exist. $ is a jQuery function equivalent to document.querySelector(). Therefore, to select the img tag you simply need to replace the <img>img. This is all what can be interpreted from the code provided by you!

Final Code Compilation:

for (var i = 0; i < 100;   i){                         
   $("#class1-images").prepend($('img',{id:'theImg',src:'training_images/class1/frame'   i   ".jpg"})                             
)}

CodePudding user response:

Your script should work - provided the target element exists and there are images behind the added URLs:

for (var i = 0; i < 100;   i){                         
   $("#class1-images").prepend($('<img>',{id:'theImg',src:`https://picsum.photos/id/${i}/200/150`})                             
)}
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<div id="class1-images"></div>

  • Related