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


Groups > comp.lang.javascript > #14147

Re: Adding to onclick

Message-ID <1595535.oMNUckLgyt@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-05-25 10:10 +0200
Subject Re: Adding to onclick
Newsgroups comp.lang.javascript
References <wf-dnWElyKFmcSPSnZ2dnUVZ_rOdnZ2d@westnet.com.au>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Andrew Poulos wrote:

> I have some code that "applies" a transformation to an element. Its
> written in such a way that multiple transformations can be applied
> simultaneously.
> 
> One of the possible triggers includes the onclick event. This works fine
> for one transformation:
> 
> elem.onclick = function() { //transformation01... };
> 
> but for multiple transformations its creating:
> 
> elem.onclick = function() { //transformation01... };
> elem.onclick = function() { //transformation02... };
> elem.onclick = function() { //transformation03... };
> ...
> 
> How can I get subsequent functions to include the code from any previous
> function?

Use either elem.addEventListener() or closures if the former is unavailable.  
(Do not use elem.attachEvent(); execution order is not guaranteed then.)

jsx.dom.addEventListener() does that for you:

<http://PointedEars.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fdom%2Fevents.js>
<http://PointedEars.de/scripts/dom/events.js> (please copy before use)


PointedEars
-- 
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
  -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)

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


Thread

Adding to onclick Andrew Poulos <ap_prog@hotmail.com> - 2012-05-25 12:22 +1000
  Re: Adding to onclick "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-05-24 20:06 -0700
    Re: Adding to onclick "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-25 07:07 +0000
  Re: Adding to onclick Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-25 10:10 +0200
  Re: Adding to onclick SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-05-25 10:26 +0200

csiph-web