Everytime I click on I a button I want the existing image on my webpage to be replace with a new image similar what happens when you click a button on this page:
But instead, it just adds new images each time , rather than replace the existing one:
Maybe the first thing the button does is replace the img with an empty string.
I’m not sure about the .appendChild(). Is there a method that’s the equivalent of .pop() for working with elements in the DOM?
Maybe try replaceChild()
(edit) ack - this requires two args (the old and the new). might not work
Kinda hacky but -
image.innerHTML will equal an empty string or a semicolon??
would appendChild now work?
Yeah, that’s kinda confusing. The image.innerHTML is set to an empty string at the beginning of the function. The rest of the code as is - with the appendChild method - should work now.
That technique you suggested worked . Thanks