Hi, When you replace an element, the old element is no longer displayed (ideally it no longer exists) and a new element is put in its place. Any event handlers associated with the old element are not automatically transferred to the new one.
There are a couple of ways to handle this: 1. Event Delegation: If you can handle events on the container containing B, rather than on B itself, then you'll be fine since you're not replacing the container. Clicks and most other events "bubble up" from the child elements to their ancestors, so this can be a powerful approach. For instance, I have an app with a bunch of links that trigger client-side actions (rather than actually going somewhere). I don't look the "click" event on each link, that would be horribly inefficient. Instead, I hook the "click" event on the container all of these links are in, and then when I get the event I ask what link triggered it via Event#findElement[1]. 2. If event delegation won't work for you, you'll need to unhook all of your handlers on B before replacing it, then hook them up to the new B after replacing it. If you don't unhook your handlers before you replace B, you'll probably leak some memory on every update; and of course if you don't hook up the new handlers you won't see the clicks. [1] http://prototypejs.org/api/event/findElement HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Aug 20, 12:19 am, hass <[email protected]> wrote: > I have set up a relatively straight forward scenario where i have a > listener for event A. On click of A (a button), I run an ajax request > to update a div B. B was a large div, representing one of 3 panels on > a page. B had some javascript functionality (lets call this event C) > inside of it which worked prior to clicking A, but after clicking A, > it no longer works. I know this is a DOM issue, but I've got to think > there is a good way around this. Any ideas? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
