preface

Recently, I saw the source code of station B video analysis Vue. When ANALYZING the parser, I saw a method to determine whether the EL parameter passed in new Vue() is node information. This method involves judging the current parameter nodeType type. I haven’t been paying attention to this before, so make a note of it.

Definitions and Usage

The nodeType property returns the nodeType. Node.nodetype is usually used to get the node type. Common node types are as follows:

  • If the node is an element node, the nodeType attribute returns 1.

  • If the node is an attribute node, the nodeType attribute returns 2.

  • If the node is a text node, the nodeType attribute returns 3.

  • If the node is an annotation node, the nodeType attribute returns 8.

This property is read-only.

Summary of Node Types

An HTML or XML document has different node types for files, elements, attributes, and so on.

There are 12 different node types, and different node types can have different child node types:

The node type node describe Child nodes NodeName return value NodeValue return value Named Constant (static variable name)
1 Element One of the elements Element, Text, Comment, ProcessingInstruction, CDATASection, Entity Reference manual Element names null ELEMENT_NODE
2 Attr An attribute Text, Entity Reference manual The property name Attribute values ATTRIBUTE_NODE
3 Text The textual content or attributes of an element None TEXT_NODE CDATA_SECTION_NODE
4 CDATASection The CDATA portion of a document (the text will not be parsed by the parser) None #text Node content
5 Entity Reference Document Entity reference Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Node content Entity reference name null ENTITY_REFERENCE_NODE
6 Entity is an Entity. Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference manual The entity name null ENTITY_NODE
7 ProcessingInstruction A processing instruction None target Contents of nodes PROCESSING_INSTRUCTION_NODE
8 Comment A comment None #comment Annotation text COMMENT_NODE
9 Document The entire document (root of the DOM tree) Element, ProcessingInstruction, Comment, DocumentType #document null DOCUMENT_NODE
10 DocumentType Provide interfaces for document entities None doctype name null DOCUMENT_TYPE_NODE
11 DocumentFragment Represents adjacent nodes and their subtrees. Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference manual #document fragment null
12 Notation Represents a declaration of a symbol in a DTD None Symbolic names null NOTATION_NODE