当前位置:网站首页>DOM node operation
DOM node operation
2020-11-07 17:19:00 【Irving the procedural ape】
DOM Node operation
1. Node Overview
The three basic properties of a node :
- Node type nodeType
- The name of the node nodeName
- Node values nodeValue
- Element nodes nodeType by 1( The main operation in actual development )
- Attribute node nodeType by 2
- Text node nodeType by 3( The text node contains text 、 Space 、 Line break, etc )
2. Node level
utilize DOM Trees can divide nodes into different hierarchical relationships , Common is Father son brother hierarchy .
2.1 Parent node
node.parentNode
- parentNode Property can return the nearest parent of a node
- If the specified node has no parent , Then return to nill
2.2 Child node
1.parentNode.childNodes // standard
parentNode.childNode Returns a collection of children of a specified node , The set is an instant update set .
notes :
- The return value contains all nodes , Include element nodes 、 Text nodes, etc
- If you just want to get the element nodes inside , It needs to be dealt with specially . So it is not recommended to use childNodes
// Just want to get the processing of the element node inside var eg = document.querySelector('ol');for(var i = 0;i < ol.childNodes.length;i++) { if (ol.childNodes[i].nodeType == 1) { // So you can pick out the element nodes ...... }}
2.parentNode.children // Nonstandard
parentNode.children Is a read-only property , Returns all child element nodes . It only returns child element nodes . Although it's nonstandard , But it's supported by various browsers , So it can be used safely .
3.parentNode.firstChild
parentNode.firstChild Return to the first child node , No return found null. The return value contains all nodes , Include element nodes 、 Text nodes, etc .
4.parentNode.lastChild
parentNode.lastChild Returns the last node , No return found null. The return value contains all nodes , Include element nodes 、 Text nodes, etc .
5.parentNode.firstElementChild
parentNode.firstElementChild Returns the first child node , No return found null.
6.parentNode.lastElementChild
parentNode.lastElementChild Returns the last child element node , No return found null.
notes :5、6 Methods have compatibility issues ,ie9 The above supports .
because firstChild and lastChild Include other nodes , and firstElementChild and lastElementChild There's a compatibility issue , therefore The solution to get the first or last child element node is :
- If you want the first child element node , have access to parentNode.children[0]
- If you want the last child element node , have access to parentNode.children[parentNode.children.length-1]
2.3 Brother node
1.node.nextSibling
nextSibling Returns the next sibling node of the current element , No return found null. The return value contains all nodes , Include element nodes 、 Text nodes, etc .
2.node.previousSibling
previousSibling Returns a sibling node on the current element , No return found null. return .........
版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢
边栏推荐
- About Devops seven misunderstandings, 99% of people have been hit!
- Nonvolatile MRAM memory used in all levels of cache
- Knowledge competition of garbage classification
- 把 4个消息队列都拉到一个群里后,他们吵起来了
- Stm32f030c6t6 compatible to replace mm32spin05pf
- 如何创建交互式内核密度图表
- Chinese sub forum of | 2020 PostgreSQL Asia Conference: Pan Juan
- 关于DevOps的七大误解,99%的人都曾中过招!
- JS string - string string object method
- Logo design company, Nanjing
猜你喜欢
傲視Kubernetes(一):Kubernetes簡介
Plug in bilibilibili new version 0.5.5
How to create an interactive kernel density chart
How does LeadTools detect, read and write barcodes
.NETCore3.1+ Vue.js Low code workflow engine
Two dimensional code location and alarm system of Expressway
C# 枚举权限 |和||,&和&&的区别
11.Service更新
如何使用甘特图图层和筛选器
9.集群之间服务通信 RoutingMesh
随机推荐
课堂练习
傲視Kubernetes(一):Kubernetes簡介
About Devops seven misunderstandings, 99% of people have been hit!
8. Swarm creates maintenance and horizontal extension service
How to create an interactive kernel density chart
滴滴的分布式ID生成器(Tinyid),好用的一批
pc端与移动端适配解决方案之rem
The advantages and functions of psychological counseling app
C語言重點——指標篇(一文讓你完全搞懂指標)| 從記憶體理解指標 | 指標完全解析
Blazor 準備好為企業服務了嗎?
Test the necessary skill points of siege lion! This article takes you to interpret the testing technology under Devops
Key points of C language -- index article (let you fully understand indicators) | understand indicators from memory | complete analysis of indicators
Application of UHF RFID medical blood management system
Design pattern of facade and mediator
课堂练习
【笔记】Error while loading PyV8 binary: exit code 1解决方法
嘉宾介绍|2020 PostgreSQL亚洲大会中文分论坛:潘娟
Nonvolatile MRAM memory used in all levels of cache
In 2020, how can wechat seal numbers be quickly lifted?
Insomnia all night