Document Object Model

In this chapter you will learn:

  1. What is DOM

What is DOM

HTML document can be represented as a hierarchy of nodes using the DOM.

For the following html code:

<html>/*from  j  a  va 2  s. co m*/
    <head>
        <title>Sample Page</title>
    </head>
    <body>
        <p id='myP'>Hello World!</p>
    </body>
</html>

Its DOM tree is

null

The root is document node. The only child of the document node is the <html> element.

<html> element is called the document element. The document element is the outermost element.

p is an HTML element and body is also an HTML element. myP is an attribute.

HTML elements are represented by element nodes. attributes are represented by attribute nodes. Each node has a type. Nodes have node type, attributes have node type and comments have comment type. The element node and attribute are different in term of type.

In total, there are 12 node types, all of which inherit from a base type.

Next chapter...

What you will learn in the next chapter:

  1. What are the node types
  2. How to determine the node type
  3. Compare node type to a numeric value
Home » Javascript Tutorial » DOM
Document Object Model
Node Type
nodeName and nodeValue
childNodes
parentNode
previousSibling and nextSibling
lastChild and firstChild
appendChild
insertBefore
ownerDocument
removeChild
replaceChild
Text
NodeList Length
DOM classes