pelachrum — 2011-01-31T17:20:44-05:00 — #1
I have an image inside of a div that I'd like to swap every time the function is triggered. I was able to attach first image through this:
this.titlecontainer.appendChild(document.createElement('img')).src = 'images/picture' + padded_index + '-t.png';
This indeed does add another image on each function iteration but as the code suggests, it actually APPENDS additional images. Instead, I'd like to SWAP the existing image for a new one. My guess is to remove what's currently loaded inside the div prior to appending another one. What would the line preceding the above have to look like to accomplish removing of the content?
force — 2011-01-31T17:26:37-05:00 — #2
Instead of appending a new child element, just change the src of the existing img.
document.getElementById('myimg').src = 'images/picture' + padded_index + '-t.png';
pelachrum — 2011-01-31T17:44:31-05:00 — #3