with Event delegation, you don't have to attach events to elements,

you'll just attach the events to the container, and it will still work even
if you change the Dom.

http://mootools.net/docs/more/Element/Element.Delegation


On Tue, Feb 16, 2010 at 6:21 PM, apathetic <[email protected]> wrote:

> I know this may be a common question, but I've been unable to find a
> satisfactory answer and I'd like to know once and for all if it's
> possible to do this:
>
> I have a container div that is reloaded via an AJAX call. However,
> inside this div there are quite a few other divs, buttons, etc, that I
> have attached events to. When the AJAX updates the container div, all
> attached events/functions are lost. I would, of course, prefer to keep
> this functionality and not have to re-bind everything after each
> successful AJAX call.
>
> After seeing a post from Aaron Newton at
>
> http://n2.nabble.com/Handling-the-changing-DOM-structure-with-AJAX-forms-td1623247.html
> ,
> I got the idea to create a Class and pass it the container div, and
> then let the Class maintain the state of my application. However, this
> is where I run into problems-- I'm not sure how I can maintain the
> state of my added events this way. Is there some way a Class can
> remember what functions/events have been bound to the children of the
> element passed to it, so that they won't need to be re-bound upon each
> AJAX call?
>
> Here's a stripped down example of what I'm talking about:
>
> http://mootools.net/shell/5PgCL/6/
>
> I've attached events to div's one, two, and three, but these are lost
> when the container is reloaded. I pass the container div to the Class
> but am currently doing nothing with it.
>
> If anyone has any thoughts please share!
>



-- 
http://tbela99.blogspot.com/

fax : (+33) 08 26 51 94 51

Reply via email to