Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19371
| From | Tuxedo <tuxedo@mailinator.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Delete onload event handler initiated at img tag level? |
| Date | 2013-04-19 21:09 +0200 |
| Organization | albasani.net |
| Message-ID | <kks4ot$u9p$1@news.albasani.net> (permalink) |
| References | <kkroc8$26t$1@news.albasani.net> <517167ab$0$6572$9b4e6d93@newsspool3.arcor-online.net> |
Martin Honnen wrote:
> 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="...">
>
>
Thanks for this neat solution, which can work similarly with
getElementById() but not with 'this' keyword. Either way, no need for the
delete operator.
Tuxedo
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar
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