search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

HTML DOM node

Collection 49
Read 20130
update time 2016-09-11

In the HTML DOM, everything is a node. DOM is HTML viewed as a tree of nodes.


DOM Nodes

DOM Nodes

According to the W3C’s HTML DOM standard, all content in an HTML document is a node:

  • The entire document is a document node

  • Each HTML element is an element node

  • The text within the HTML element is a text node

  • Each HTML attribute is an attribute node

  • Comments are comment nodes


HTML DOM node tree

HTML DOM treats HTML documents as a tree structure. This structure is called a node tree:

HTML DOM tree instance

DOM HTML tree

pic_htmltree.gif

Node parent, child and sibling

Nodes in the node tree have a hierarchical relationship with each other.

The terms parent, child, and sibling are used to describe these relationships. Parent nodes have child nodes. Children of the same level are called siblings (brothers or sisters).

  • In the node tree, the top node is called the root (root)

  • Every node has a parent node, except the root (it No parent node)

  • A node can have any number of children

  • Siblings are nodes with the same parent node

The picture below shows a part of the node tree, and the relationship between nodes:

7.png


Please see below HTML fragment:

<html>
<head>
<title>DOM Tutorial</title>
</head>
< body>
;

From the HTML above:

  • <html> node has no parent; it is the root node

  • <head> The parent node of <body> is the <html> node

  • The parent node of the text node "Hello world!" is the <p> node

And:

  • <html> node has two child nodes: <head> and <body>

  • ##< The ;head> node has one child node: <title> node

  • <title> The node also has one child node: text node "DOM Tutorial"

  • <h1> and <p> nodes are sibling nodes and are also child nodes of <body>

And:

  • The<head> element is the first child node of the <html> element

  • The<body> element is the last child node of the <html> element

  • <h1> element is the first child node of the <body> element

  • ##<p> element is the last child node of the <body> element Child node
Warning!

A common mistake in DOM processing is expecting element nodes to contain text.

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

The value of a text node can be accessed through the node's innerHTML property.

You will learn more about the innerHTML property in later chapters.

Hot AI Tools
Undress AI Tool
Undress AI Tool

Undress images for free

AI Clothes Remover
AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress
Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT
ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT
Stock Market GPT

AI powered investment research for smarter decisions

Popular tool
Notepad++7.3.1
Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version
SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1
Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6
Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version
SublimeText3 Mac version

God-level code editing software (SublimeText3)