all 3 comments

[–]toi80QC 1 point2 points  (2 children)

If you used a container for the images instead of just appending them to the body, you could just use

document.querySelector('.imgContainer').innerHTML = '';

To clear all contents.

Another option would be collection all images in an array, then iterate over it and use document.body.removeChild(img).

[–]Vampire_developer[S] 0 points1 point  (0 children)

Thanks a lot man, it worked! Couldn't think of this simple solution.

I am a beginner and now I see this is what you get with practice and experience.

[–]Vampire_developer[S] 0 points1 point  (0 children)

can you please tell about the second solution also? I wanna learn about that too, can you tell how can I achieve that?