Riccardo De Agostini
2007-Oct-03 13:09 UTC
Prototype 1.5.1.1 / 1.6_rc0: bug in Element.remove()?
Hello everyone.
I might have found a bug in the Element.remove() method (in both
Prototype 1.5.1.1 and 1.6.0_rc0, since the method''s code has not
changed). If I try to remove an element from the document this way:
myElement.remove(); // myElement has already been extended, of course
or:
Element.remove(myElement);
I get an error message (Firefox 2.0.0.6 + Firebug, on Ubuntu 7.04)
stating that element.parentNode has no methods. The following code,
instead, works as expected:
var parent = $(myElement.parentNode);
parent.removeChild(myElement);
I had a look at the source code for Element.remove and her''s what I
found:
remove: function(element) {
element = $(element);
element.parentNode.removeChild(element); // <--- Notice this line
return element;
},
Looks like I need to extend parentNode before the removeChild methos
becomes available, even if it is not, theoretically speaking, a
Prototype-defined method.
Does this ring a bell to anyone? As a matter of fact, Prototype''s own
documentation (see last section of http://www.prototypejs.org/learn/extensions
) warns against using Element''s methods on elements which have not
been explicitly extended, citing as an example elements obtained via
the parentNode method.
So the line above should become, as far as I understand:
$(element.parentNode).removeChild(element); // <--- It works now!
Am I just drinking too much coffee these days? :-) I mean, I can''t
believe there''s a bug like this in Prototype. Can anyone confirm (or,
more probably, tell me what I did wrong in my code)?
Thanks in advance
Ric
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---