spacer

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

home / experts / javascript / column88


Internet Explorer 6, Part I: DOM Standards Support

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Finding the Node's DOM Context

The DOM models an HTML document as a tree. The root of the tree is the document object. The node representing the root is document.documentElement. Internet Explorer supports a new relationship: 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. This ownership relationship is given by the ownerDocument property. If we model the whole document by a single DOM tree, the ownerDocument property is a direct pointer from any node on the DOM tree to 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 recognize which node it is. You should get HTML. 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 the 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 shown, let's print the node name. Again, we go to the root node by the documentElement property:

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

You should get HTML.

Next: A Final Word

More Resources from Doc JavaScript
Columns Popular Columns Tips Tools
Latest Columns
41-50 | 31-40 | 21-30
11-20 | 1-10
Working with Windows
JavaScript and Frames
Bookmarklets
Random Tips
Personalized Tips
RSS Channels
Menu Builder
Rollover Builder
Rotation Builder
Reference Tip Categories (want one?)
Links
For Your Site
Did you learn something? Do you like this site? Please link to us!

http://www.internet.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


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

URL: http://www.webreference.com/js/column88/8.html