Geeks With Blogs
Kendall's .net workarounds Short fixes and problems encountered in everyday c# live
I realize the following won't have many working examples.  If someone would like a working example of what the heck I'm talking about. Feel free to ask, and I'll create a few.

In the application I'm working on, I had a situation where I wanted to show/hide a div tag to conserve screen real estate.  Pretty simple to do.  However, using CSS with relative positioning I quickly ran into problems with the section being shown overlapping frames and objects beneath it.  I needed to increase the size of the parent container in order order to make sure that the newly shown div didn't overlap objects beneath it.

After some quick experimentation I found begin simply setting the obj.parentElement.style.height property.  Everthing seemed fine in my javascript.  So today I'm playing around with what I've done in production when I find that when I click the button to open the div tag, it would do a postback.  After some quick legwork I found that in firefox parentElement doesn't evalutate.  Some quick searching on the internet found that the preferred method was to use parentNode instead.  This seemed to also work with Internet Explorer.  Changing it to use parentNode worked great.


A firefox tool that really made it easier to work with this problem is Firebug.  It allows you to breakpoint javascript and inspect errors and variables.
https://addons.mozilla.org/en-US/firefox/addon/1843 Posted on Tuesday, August 21, 2007 12:00 PM | Back to top


Comments on this post: parentNode vs ParentElement javascript.

# re: parentNode vs ParentElement javascript.
Requesting Gravatar...
Thanks for this post. I encountered this problem in Firefox and couldn't understand why I was getting an error.
Left by Ryan on Dec 10, 2008 9:40 AM

# re: parentNode vs ParentElement javascript.
Requesting Gravatar...
Thanks. I too had this problem and the parentNode resolved the problem.
Left by Gary on May 27, 2009 9:49 AM

# re: parentNode vs ParentElement javascript.
Requesting Gravatar...
So for a quick summary, parentNode works, parentElement doesn't.
Left by iGuide on Jun 10, 2009 8:21 PM

# re: parentNode vs ParentElement javascript.
Requesting Gravatar...
Thanks. Good explanation and just what I was looking for.
Left by Tomas on Jun 24, 2009 7:36 AM

# re: parentNode vs ParentElement javascript.
Requesting Gravatar...
That was really helpful.
Thanks a lot.
Left by madhan on Oct 14, 2009 5:56 AM

# re: parentNode vs ParentElement javascript.
Requesting Gravatar...
Thankzz guyzzz... It helped me out too :)
Left by PSingh on Mar 16, 2010 2:48 PM

# re: parentNode vs ParentElement javascript.
Requesting Gravatar...
A nugget of gold dust. Thx.
Left by Kaine Varley on Feb 15, 2011 9:38 AM

# re: parentNode vs ParentElement javascript.
Requesting Gravatar...
Thanks alot. The solution worked like charm.
Left by Ken Omondi on Aug 15, 2011 2:19 AM

Your comment:
 (will show your gravatar)


Copyright © Kendall | Powered by: GeeksWithBlogs.net