Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19366

Re: Delete onload event handler initiated at img tag level?

Date 2013-04-19 17:50 +0200
From Martin Honnen <mahotrash@yahoo.de>
Organization Liberty Development
Newsgroups comp.lang.javascript
Subject Re: Delete onload event handler initiated at img tag level?
References <kkroc8$26t$1@news.albasani.net>
Message-ID <517167ab$0$6572$9b4e6d93@newsspool3.arcor-online.net> (permalink)

Show all headers | View raw


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="...">


-- 

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Delete onload event handler initiated at img tag level? Tuxedo <tuxedo@mailinator.com> - 2013-04-19 17:37 +0200
  Re: Delete onload event handler initiated at img tag level? Martin Honnen <mahotrash@yahoo.de> - 2013-04-19 17:50 +0200
    Re: Delete onload event handler initiated at img tag level? Tuxedo <tuxedo@mailinator.com> - 2013-04-19 21:09 +0200

csiph-web