spacer
Yehuda Shiran December 20, 2000
The Document's Virtual Root Node
Tips: December 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

You can use the DOM (Document Object Model) to model the whole document. At the root of document model is the document object. But this node is only virtual: you cannot prompt its type, name, or ID. You can access these properties through the documentElement object attribute. If you would query the name of document.documentElement:

document.documentElement.nodeName

you would get HTML. Try it. You may also query the root's type:

document.documentElement.nodeType

You should get 1. Try it. There are three types:

  • 1 = Tag (Examples: HTML, BODY, HEAD)
  • 2 = Attribute (Examples: ID, NAME, BGCOLOR)
  • 3 = Text (Free text between opening and closing tags. Example: text between <P> and </P>)

The node document.documentElement is the root of the document model. If you would query its first child:

document.documentElement.firstChild.nodeName

you would get the HEAD tag. Try it.

The code in this tip can be viewed by all DOM-supporting browsers such as IE 5+ and Netscape 6.

Learn more about the DOM in Columns 40, The DOM, Part I: Analysis, through Column 47, A DOM-Based Snakes Game, Part II.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint