w3schools    w3Schools
Search :
   
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About
ADVERTISEMENTS

XML Certification
Download XML editor
Custom Programming
 
Table of contents
HTML DOM
DOM HOME
DOM Intro
DOM Nodes
DOM Node Tree
DOM Methods
DOM Node Access
DOM Node Info
DOM How To
DOM Events
DOM Reference
DOM Summary

DOM Examples
DOM Examples

DOM Objects
DOM Window
DOM Navigator
DOM Screen
DOM History
DOM Location

DOM Document

DOM Anchor
DOM Area
DOM Base
DOM Body
DOM Button
DOM Event
DOM Form
DOM Frame
DOM Frameset
DOM IFrame
DOM Image
DOM Input Button
DOM Input Checkbox
DOM Input File
DOM Input Hidden
DOM Input Password
DOM Input Radio
DOM Input Reset
DOM Input Submit
DOM Input Text
DOM Link
DOM Meta
DOM Object
DOM Option
DOM Select
DOM Style
DOM Table
DOM TableCell
DOM TableRow
DOM Textarea

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

Browse Tutorials
 

HTML DOM Nodes

previous next

In the DOM, everything in an HTML document is a node.


Nodes

According to the DOM, everything in an HTML document is a node.

The DOM says:

  • The entire document is a document node
  • Every HTML tag is an element node
  • The text in the HTML elements are text nodes
  • Every HTML attribute is an attribute node
  • Comments are comment nodes

DOM Example

Look at the following HTML document:

<html>
  <head>
    <title>DOM Tutorial</title> 
  </head> 
  <body> 
    <h1>DOM Lesson one</h1> 
    <p>Hello world!</p> 
  </body> 
</html>

The root node in the HTML above is <html>. All other nodes in the document are contained within <html>.

The <html> node has two child nodes; <head> and <body>.

The <head> node holds a <title> node. The <body> node holds a <h1> and <p> node.


Text is Always Stored in Text Nodes

A common error in DOM processing is to expect an element node to contain text.

However, the text of an element node is stored in a text node.

In this example: <title>DOM Tutorial</title>, the element node <title>, holds a text node with the value "DOM Tutorial".

"DOM Tutorial" is not the value of the <title> element!

However, in the HTML DOM the value of the text node can be accessed by the innerHTML property.

You can read more about the innerHTML property in a later chapter.


previous next