Hey,
http://brandonaaron.net/docs/livequery/
Destroying events connected to a removed element helps prevent memory
leaks -- it is really the correct behavior.
Well in most cases it probably is. However I actually got my own little
"framework" used by all plugins I wrote, which attaches events to
elements, and cleans them up when I "destroy" them . However, in this
particularly case I was just temporarily removing an <a> from the DOM
while replacing it with an <input> element for editing. I've changed it
to use show() / hide() for now as it doesn't really make much of a
difference, I was just interested in why I had to do it.
I don't use livequery b/c I don't want to deal with the performance hit.
My solution is fairly similar in terms of defining hash table of
selectors to apply whenever an element is generated, but its tied into
my internal event system and knows about its scope so its not trying to
bind stuff whenever some dom manipulation method is run.
Anyway thanks alot for the explanations!!
-- Felix
--------------------------
Blogger: http://www.thinkingphp.org/
Entrepreneur: http://www.posttask.com/ /-- currently in private beta,
ask me for invite / password/
Freelancer: http://www.fg-webdesign.de/
AIM: theundefined87
Skype: TimeFor23
Other IM: felixge.de <http://felixge.de/>
Mobile (USA): +1 404 3888693
Mobile (GER): +49 162 9391612
Twitter: http://twitter.com/felixge
Jeffrey Kretz wrote:
If you haven't seen the livequery plugin, I would recommend looking it
over -- this would really be the correct solution to this.
http://brandonaaron.net/docs/livequery/
Destroying events connected to a removed element helps prevent memory
leaks -- it is really the correct behavior.
JK
------------------------------------------------------------------------
*From:* jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED]
*On Behalf Of *Felix Geisendörfer
*Sent:* Tuesday, November 06, 2007 1:46 PM
*To:* jquery-en@googlegroups.com
*Subject:* [jQuery] remove() deletes events in jQuery 1.2.1. Why?
Hey,
I recently upgraded my app from jQuery 1.3.1 to 1.2.1 and the
transition was incredibly easy.
However, yesterday I noticed that $().remove() now seems to behave
differently then it did in 1.3.1. Thats because now it deletes any
events attached to the element removed. This happens to be a problem
in my app b/c I remove unneeded elements from the DOM instead of
hiding them and inject them back in later on. So when they are
injected again, they suddenly don't "work" anymore : ).
Now I looked through the manual and it says this is going to be the
expected behavior in 1.2.2:
http://docs.jquery.com/Manipulation/remove
Which confuses me b/c it already seems to be the case in 1.2.1 and I'm
also wondering how I could remove DOM elements without deleting their
events in future? I'm also curious about why this change is being
made, is it some anti-memory leak thingy?
Thanks a lot,
-- Felix
--------------------------
Blogger: http://www.thinkingphp.org/
Entrepreneur: http://www.posttask.com/ //-- currently in private beta,
ask me for invite / password//
Freelancer: http://www.fg-webdesign.de/
*AIM:*
theundefined87
*Skype:*
TimeFor23
*Other IM:*
felixge.de <http://felixge.de/>
*Mobile** (USA):*
+1 404 3888693
*Mobile** (GER):*
+49 162 9391612
*Twitter:*
http://twitter.com/felixge