[thelist] javascript : events not firing after dom alteration

Volkan Özçelik volkan.ozcelik at gmail.com
Sat Jul 21 04:06:56 CDT 2007


Hi Shaun,

On 7/21/07, shaun at porkandpaws.com <shaun at porkandpaws.com> wrote:
>
>
> Part of the action replaces this link.


When you replace the link, you introduce a brand new  element to the  DOM
structure.
The old link and hence its old event attachments are not available any more.

Ideally;

1. You should detach all event handlers *before* altering the element (due
to memory leakage and closure issues -- good boys clean up their mess.)
2. Insert new element to DOM via appendChild or something similar (or for
the lazy men out there; setting the innerHTML of the container parent)
3. re-attach the event handler with your favorite event attachment method of
your favorite library.

HTH,
-- 
Volkan Ozcelik
+> linkibol.com - in seek of quality links: http://www.linkibol.com/
+> Going solo in Turkish: http://www.fikribol.com/donkisot/
+> My projects/studies/trials/errors : http://www.sarmal.com/
+> Sardalya JavaScript Library: http://www.sarmal.com/sardalya/



More information about the thelist mailing list