Node Object

Definition and Usage

The Node object represents a node in the HTML document.

A node in an HTML document is:

  • The Document
  • An element
  • An attribute
  • Text
  • A comment

All of the node types are explained in the Node Types reference at the bottom of this page.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The Node object is supported in all major browsers.


Node Object Properties

The "DOM" column indicates in which DOM Level the property was introduced.

Property Description DOM
attributes Returns a collection of a node's attributes 1
baseURI Returns the absolute base URI of a node 3
childNodes Returns a NodeList of child nodes for a node 1
firstChild Returns the first child of a node 1
lastChild Returns the last child of a node 1
localName Returns the local part of the name of a node 2
namespaceURI Returns the namespace URI of a node 2
nextSibling Returns the next node at the same node tree level 1
nodeName Returns the name of a node, depending on its type 1
nodeType Returns the type of a node 1
nodeValue Sets or returns the value of a node, depending on its type 1
ownerDocument Returns the root element (document object) for a node 2
parentNode Returns the parent node of a node 1
prefix Sets or returns the namespace prefix of a node 2
previousSibling Returns the previous node at the same node tree level 1
textContent Sets or returns the textual content of a node and its descendants 3

Node Object Methods

The "DOM" column indicates in which DOM Level the method was introduced.

Method Description DOM
appendChild() Adds a new child node, to the specified node, as the last child node 1
cloneNode() Clones a node 1
compareDocumentPosition() Compares the document position of two nodes 1
getFeature(feature,version) Returns a DOM object which implements the specialized APIs of the specified feature and version 3
getUserData(key) Returns the object associated to a key on a this node. The object must first have been set to this node by calling setUserData with the same key 3
hasAttributes() Returns true if a node has any attributes, otherwise it returns false 2
hasChildNodes() Returns true if a node has any child nodes, otherwise it returns false 1
insertBefore() Inserts a new child node before a specified, existing, child node 1
isDefaultNamespace() Returns true if the specified namespaceURI is the default, otherwise false 3
isEqualNode() Checks if two nodes are equal 3
isSameNode() Checks if two nodes are the same node 3
isSupported() Returns true if a specified feature is supported on a node, otherwise false 2
lookupNamespaceURI() Returns the namespace URI matching a specified prefix 3
lookupPrefix() Returns the prefix matching a specified namespace URI 3
normalize() Joins adjacent text nodes and removes empty text nodes 2
removeChild() Removes a child node 1
replaceChild() Replaces a child node 1
setUserData(key,data,handler) Associates an object to a key on a node 3


Node Types

Documents, elements, attributes, and other aspects of an HTML document has different node types.

There are 12 different node types, which may have children of various node types:

Node type Description Children
1 Element Represents an element Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
2 Attr Represents an attribute Text, EntityReference
3 Text Represents textual content in an element or attribute None
4 CDATASection Represents a CDATA section in a document (text that will NOT be parsed by a parser) None
5 EntityReference Represents an entity reference Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
6 Entity Represents an entity Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
7 ProcessingInstruction Represents a processing instruction None
8 Comment Represents a comment None
9 Document Represents the entire document (the root-node of the DOM tree) Element, ProcessingInstruction, Comment, DocumentType
10 DocumentType Provides an interface to the entities defined for the document None
11 DocumentFragment Represents a "lightweight" Document object, which can hold a portion of a document Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
12 Notation Represents a notation declared in the DTD None

Node Types - Return Values

The return value of the nodeName and the nodeValue properties for each node type:

Node type nodeName returns nodeValue returns
1 Element element name null
2 Attr attribute name attribute value
3 Text #text content of node
4 CDATASection #cdata-section content of node
5 EntityReference entity reference name null
6 Entity entity name null
7 ProcessingInstruction target content of node
8 Comment #comment comment text
9 Document #document null
10 DocumentType doctype name null
11  DocumentFragment #document fragment null
12 Notation notation name null

NodeTypes - Named Constants

NodeType Named Constant
1 ELEMENT_NODE
2 ATTRIBUTE_NODE
3 TEXT_NODE
4 CDATA_SECTION_NODE
5 ENTITY_REFERENCE_NODE
6 ENTITY_NODE
7 PROCESSING_INSTRUCTION_NODE
8 COMMENT_NODE
9 DOCUMENT_NODE
10 DOCUMENT_TYPE_NODE
11 DOCUMENT_FRAGMENT_NODE
12 NOTATION_NODE

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值