current position:Home>Introduction and classification of JavaScript DOM nodes

Introduction and classification of JavaScript DOM nodes

2021-08-25 02:39:53 Cheese Yuzhi Matcha

brief introduction

  • node (node) Is a network term , It represents a connection point in the network . A network is a collection of nodes .
  • stay DOM in , A document is a collection of nodes , At this time, the nodes are branches and leaves on the document tree .


DOM Contains many different types of nodes , Let's introduce three of them : Element nodes 、 Text nodes and attribute nodes .

1. Element nodes

explain :DOM The atom of is an element node .


  • The name of the element is the name of the tag .example: The name of the text paragraph element is “p”.
  • Element can contain other elements .example: stay html In file ,\ The element is the root element of the node tree , Other elements , for example head、body etc. , Are contained in the root element .

2. Text node

explain : Text nodes are always contained within element nodes , Its content is text . But it can't be said that all element nodes contain text nodes .


<p>This is an example.</p>

Above <p> In the elements ,“This is an example.” It's just a text node .

3. Attribute node

explain : The attribute node is used to make a more specific description of the element .


</p><p title="an example title">This is an example.</p>

Above <p> In the elements , We can use title Property to describe this </p>

Elements .

stay DOM in ,title="an example title" Is an attribute node .
 Picture example

Be careful

  • Attribute nodes are always placed in the start tag , That is, attribute nodes are always contained in element nodes .

  • But not all elements contain attributes , But all the attributes are contained in the element .

Reference books :《JavaScript DOM Programming art 》

copyright notice
author[Cheese Yuzhi Matcha],Please bring the original link to reprint, thank you.

Random recommended