Solution 1 :

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"})                             
)}

Solution 2 :

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>

Problem :

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 it’s still not working.

Comments

Comment posted by Boguz

Do you get any errors on the console? Can you show us a screenshot of your project’s files, so we can see if the path is correct? Also, notice this would create man images, all with the same ID, which isn’t a good thing

Comment posted by Vel

Show your html code

Comment posted by The Myth

@Sri Rama Punniya Vallabhar please approve any of the answers mentioned or comment if it doesn’t suffice your needs. This will help the community to identify the helpful one!

Comment posted by freedomn-m

$ is a jQuery function equivalent to document.querySelector()

Comment posted by freedomn-m

Your code will take an existing

Comment posted by The Myth

I don’t know their exact expectations since it wasn’t clearly mentioned. Simply intended to find the flaw in the existing code.

Comment posted by api.jquery.com/jquery

@freedomn-m have you gotten it all wrong?

Comment posted by api.jquery.com/jquery/#jQuery-html-attributes

Scroll down a bit further to

By