spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column75


Netscape 6, Part IV: DOM Differences and Commonalities with IE5.x

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

The Ownership Relationship

A relationship that is not yet supported by IE 5.5 is the document context of a node. Each tag you define in an HTML file (each tag is modeled by a node on the DOM tree), belongs to a certain document object. The property that denotes this ownership is ownerDocument. If we model the whole document in a single DOM tree, the ownerDocument property is a direct link between any node on the DOM tree and the root of the tree. The following expression should return the root of the DOM tree:

document.documentElement.ownerDocument

Let's print the node name (tag name), so it's easier to detect which node it is. You should get HTML as an answer. For printing the root's properties, always go the root node by using the documentElement property. The printing above is actually done via:

alert(document.documentElement.ownerDocument.documentElement.nodeName);

Now, let's go deeper in the tree, to document's first child (HEAD):

document.documentElement.firstChild

And then let's go directly back to the root of the DOM tree:

document.documentElement.firstChild.ownerDocument

As previously, let's print the node name of the root. Again, we go to the root node by the documentElement property:


alert(document.documentElement.firstChild.ownerDocument.
  documentElement.nodeName);

You should get HTML.

Next: How to reference objects in Netscape 6

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: January 15, 2001
Revised: January 15, 2001

URL: http://www.webreference.com/js/column75/4.html