Hi here is my problem : Event.observe(window, ''load'', function() { var jeux = $(''listeJeux'').getElementsByTagName(''li''); for (i = 0; i < jeux.length; i++) { Event.observe(jeux.item(i), ''click'', function(event) { alert(Event.element(event).getAttribute(''class'')); }); } }); this script list all "li" elements and observe the click events on each of them with Firefox, no problem, the alert shows correct values with IE, the alert says "null" in my real script, I need to access to Event.element(event).getAttribute(''class'') but not for an alert, this is just for the example... does someone have any idea ? thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Dia wrote:> ... > Event.observe(window, ''load'', function() { > var jeux = $(''listeJeux'').getElementsByTagName(''li''); > for (i = 0; i < jeux.length; i++) { > Event.observe(jeux.item(i), ''click'', function(event) { > alert(Event.element(event).getAttribute(''class'')); > }); > } > }); > ... > with Firefox, no problem, the alert shows correct values > with IE, the alert says "null" > ...I don''t believe the Event.element() automatically extends the element so you need $(Event.element(event)).getAttribute(''class'') Also, try shortening your code using $$() and invoke()--example below. - Ken Event.observe(window, ''load'', function() { $$(''#listeJeux li).invoke(''observe'', ''click'', function(event) { alert($(Event.element(event)).getAttribute(''class'')); }); }); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 7, 2007, at 2:49 PM, Dia wrote:> alert(Event.element(event).getAttribute(''class'')); > > with Firefox, no problem, the alert shows correct values > with IE, the alert says "null"IE doesn''t do well with getAttribute(''class''). Access className directly from the element: var str = Event.element(event).className; On Aug 7, 2007, at 4:00 PM, Ken Snyder wrote:> I don''t believe the Event.element() automatically extends the > element so > you need $(Event.element(event)).getAttribute(''class'')''Tis not so. getAttribute() is a DOM function, not a Prototype extension. Old versions of Prototype didn''t extend the element, but new versions do. Either way, as getAttribute isn''t a DOM function, it''s irrelevant here. TAG --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
@ Tom ya, I knew it but forgot... I was too tired ;) I finally used a Prototype function : classes = $A(Event.element(event).classNames()); classe = classes[0]; thanks a lot for the solution @ Ken> Event.observe(window, ''load'', function() { > $$(''#listeJeux li'').invoke(''observe'', ''click'', function(event) { > alert($(Event.element(event)).getAttribute(''class'')); > });didn''t konw the "invoke" function this code is smarter than mine, thanks for showing me this way of doing :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
In trunk, Event.element returns extended elements. Use Element#readAttribute (http://prototypejs.org/api/element/ readAttribute) to handle IE discrepancies with getAttributes. Regards, Tobie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---