*To apply a script after page loaded (all dom node loaded)* document.observe('dom:loaded', function() { $$('tr.lignealternative').each(function(elmt) { elmt.observe('mouseover', function(ev) { elmt.toggleClassName("lignehover"); }); elmt.observe('mouseout', function(ev) { elmt.toggleClassName("lignealternative"); }); }); });
*To apply a script after an ajax response:* new Ajax.Request(url, { onSuccess: function(transport) { $$('tr.lignealternative').each(function(elmt) { elmt.observe('mouseover', function(ev) { elmt.toggleClassName("lignehover"); }); elmt.observe('mouseout', function(ev) { elmt.toggleClassName("lignealternative"); }); }); } }); On Thu, Mar 18, 2010 at 4:46 AM, Joannes De KOSTER < joannes.dekos...@gmail.com> wrote: > Hello, > > How can i apply a script on an html element (for example a table) when > this element is loaded in the page afterwards (after ajax request)? > > This code never gets to work for example : > > > > $$('tr.lignealternative').each(function(elmt) { > elmt.observe('mouseover', function(ev) { > elmt.toggleClassName("lignehover"); > }); > elmt.observe('mouseout', function(ev) { > elmt.toggleClassName("lignealternative"); > }); > }); > > Because the table gets loaded after an ajax request, when the page is > already loaded. > > Thanks. > > Joannes > > -- > 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 > prototype-scriptacul...@googlegroups.com. > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculous%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > > -- 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 prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.