Blog Stats
  • Posts - 5
  • Articles - 0
  • Comments - 12
  • Trackbacks - 0

 

parentNode vs ParentElement javascript.

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
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: parentNode vs ParentElement javascript.

Gravatar Thanks for this post. I encountered this problem in Firefox and couldn't understand why I was getting an error. 12/10/2008 9:40 AM | Ryan

# re: parentNode vs ParentElement javascript.

Gravatar Thanks. I too had this problem and the parentNode resolved the problem. 5/27/2009 9:49 AM | Gary

# re: parentNode vs ParentElement javascript.

Gravatar So for a quick summary, parentNode works, parentElement doesn't. 6/10/2009 8:21 PM | iGuide

# re: parentNode vs ParentElement javascript.

Gravatar Thanks. Good explanation and just what I was looking for. 6/24/2009 7:36 AM | Tomas

# re: parentNode vs ParentElement javascript.

Gravatar That was really helpful.
Thanks a lot. 10/14/2009 5:56 AM | madhan

# re: parentNode vs ParentElement javascript.

Gravatar Thankzz guyzzz... It helped me out too :) 3/16/2010 2:48 PM | PSingh

# re: parentNode vs ParentElement javascript.

Gravatar A nugget of gold dust. Thx. 2/15/2011 9:38 AM | Kaine Varley

# re: parentNode vs ParentElement javascript.

Gravatar Thanks alot. The solution worked like charm. 8/15/2011 2:19 AM | Ken Omondi

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Kendall