Tuxedo wrote:
> For example, the following would repeat the replacement indefinitely as the
> image is replacing itself with itself:
>
> function replace(){
> document.getElementById("photo").src="pic2.jpg";
> // delete onload???
> }
> <img src="pic1.jpg" onload="replace()" id="photo">
>
> Is there way to effectively remove the event while having the onload event
> handler in the image tag as above so it only happens once?
>
> Maybe something like:
> delete document.getElementById("photo").onload; // ???
I would use
function replace(img, imgUrl) {
img.onload = null;
img.src = imgUrl;
}
<img src="pic1.jpg" onload="replace(this, 'pic2.jpg');" alt="...">
--