Home  >  Article  >  Web Front-end  >  How to get all data in the DOM document tree

How to get all data in the DOM document tree

php中世界最好的语言
php中世界最好的语言Original
2018-06-11 15:19:571349browse

This time I will show you how to obtain all the data in the DOM document tree, and what are the precautions for obtaining all the data in the DOM document tree. The following is a practical case, let's take a look.

1 Introduction

Traversing the document tree is achieved by using the parentNode attribute, firstChild attribute, lastChild attribute, previousSibling attribute and nextSibling attribute.

1, parentNodeAttribute

This attribute returns the parent node of the current node.

[pNode=]obj.parentNode

pNode: This parameter is used to store the parent node. If the parent node does not exist, "null" will be returned.

2, firstChildAttribute

This attribute returns the first child node of the current node.

[cNode=]obj.firstChild

cNode: This parameter is used to store the first child node. If it does not exist, "null" will be returned.

3, lastChildAttribute

This attribute returns the last child node of the current node.

[cNode=]obj.lastChild

cNode: This parameter is used to store the last child node. If it does not exist, "null" will be returned.

4, previousSiblingAttribute

This attribute returns the previous sibling node of the current node.

[sNode=]obj.previousSibling

sNode: This parameter is used to store the previous sibling node. If it does not exist, "null" will be returned.

5, nextSiblingAttribute

This attribute returns the next sibling node of the current node.

[sNode=]obj.nextSibling

sNode: This parameter is used to store the next sibling node. If it does not exist, "null" will be returned.

Second Application

Traverse the document tree. On the page, you can find the name, type and number of each node of the document through the corresponding button. node value.

Three codes


遍历文档树

三号标题

加粗内容
节点名称:
节点类型:
节点的值:

Four running results

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Summary of JS insertion method of DOM object node

How to operate babel conversion es6

The above is the detailed content of How to get all data in the DOM document tree. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn