0

How To Show Image When Press Button (Solved)

how to make every time we press the button will display unlimited images, my problem is that I can only display 1 image when I press the button again the image does not appear :( https://code.sololearn.com/W7cfJfeBYr9s/?ref=app

8th Jun 2021, 6:45 PM
hafidz ridwan cahya
hafidz ridwan cahya - avatar
2 Respuestas
+ 1
hafidz ridwan cahya Write these const container=document.getElementById('container'); // Add trophy const trophyImg = document.createElement("img"); trophyImg.src="https://img.icons8.com/office/80/000000/trophy--v2.png"; inside show function https://code.sololearn.com/W6VIto49agCB/?ref=app
8th Jun 2021, 7:28 PM
A͢J
A͢J - avatar
+ 1
your code is not working in (at least android) app'... to make your code more safe (working in all contexts), you should wrap your js code in an onload event function handler (and export to global scope the function used in html onclick button): onload = () => { window.show = show; // put your code here }; now, to append 'unlimited images' you must append new (cloned) node rather than append the same node (wich will first remove it from its parent then insert it at the new target parent): container.appendChild(trophyImg.cloneNode());
8th Jun 2021, 7:05 PM
visph
visph - avatar