PDA

View Full Version : Duplicating nodes - parentNode issues?


crenner
05-10-2005, 06:50 AM
I'm working on a script to duplicate a node, inserting the new node after the old. It works just fine in Firefox, but i'm getting inexplicable errors in Safari and IE.

http://www.rserv.info/misc/dupetest.html

Everything I read indicates that the parentNode property works in all major browers, but IE/mac gives me an error "Object doesn't support this property or method" on "parent = toDupe.parentNode;"

safari doesn't mind that line, but says "value undefined (result of expression parent.replaceChild) is not object" on the replaceChild call.

I can't understand why this would work just fine in Firefox, but not in any other browser. Any ideas?

glenngv
05-10-2005, 07:47 AM
You didn't use var to declare the variable parent making it global and points to the built-in object window.parent. That caused a "Not implemented" error in IE/Win on line parent = toDupe.parentNode, because you're setting the parent window object to a document node.

Lesson learned: Always use var to declare local variables to avoid unexpected errors.

crenner
05-10-2005, 08:05 AM
Doh! Well, thanks for the lesson. I guess that's what happens when I try to learn a language just by looking at code, and not actually reading a book. It now works in safari, and ie/mac is handling that piece of code alright. Of course, ie/mac is still having some crazy issues with the deep clone, but I'm willing to write off the bug ridden crash prone piece of junk (http://www.quirksmode.org/browsers/explorer5mac.html).

Thanks for the help.