Walter, I think you answered my question in your first paragraph, namely about the page knowing only about the elements existing inside an opening and closing of an event firing.
Quite amazing how hard a concept that was for me to grasp from reading the Prototype API and tutorials pages. I guess that is more of a cross- browser DOM fact, and the Prototype folks probably assume that we should know that. You learn something new everyday. Thank you for your answer and example. Best, neorou On Feb 4, 8:29 am, Walter Lee Davis <[email protected]> wrote: > When you set a listener on dom:loaded, what happens is that any > closures (anonyomous functions) inside that listener "close" around > the current values found in the page at the moment that the event > fires. Adding a new element to the page does not "open" those closures > and give them access to the new elements, instead, they only know > about what was there when the page was loaded. > > In contrast, you can listen to the event you are interested in at a > level of the DOM above where your elements are -- a parent into which > you insert your new elements -- and because that parent was there when > the page loaded, the listener will work. Try this modification of your > code: > > document.observe('dom:loaded'), function(){ > document.observe('click', function(evt){ > var elm; > // listen to all click events on buttons with 'remove-site- > button' class > if(elm = evt.findElement('.remove-site-button')) { > var rsb = Event.element(eve).up('table').remove(); > } > }); > > }); > > Walter > > On Feb 3, 2011, at 3:55 PM, neorou wrote: > > > My question has to do with why the event listener at the end of my > > javascript file does not 'listen' to the newly generated buttons in > > the new 'site-info' tables. I am guessing it is because the new > > tables/ > > buttons were generated after the dom:loaded event at the document > > level? -- 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.
