当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 【QT】QThread原始碼淺析
- ImageMagick - 添加水印
- 20 XR projects roadshows, nearly 20 capital institutions attended! We sincerely invite you to attend the 2020 qcomm XR eco Partner Conference
- Win7 AppCrash (solution)
- Exclusive interview with Yue Caibo
- 【原創】ARM平臺記憶體和cache對xenomai實時性的影響
- JS array the usage of array is all here (array method reconstruction, array traversal, array de duplication, array judgment and conversion)
- Introduction to Jenkins (2) declarative pipeline
- Benefits and functions of auto maintenance app development
- A good thing for working people -- to temper the will of iron and steel requires such an efficient computer
猜你喜欢
如何解决谷歌Chrome浏览器空白页的问题
vue踩坑:axios使用this指针
Configuration of AP hotspot on xunwei-imx6ull development board
confd
9.集群之间服务通信 RoutingMesh
9. Routingmesh service communication between clusters
关于DevOps的七大误解,99%的人都曾中过招!
Stm32f030f4p6 compatible with smart micro mm32f031f4p6
【笔记】Error while loading PyV8 binary: exit code 1解决方法
傲視Kubernetes(一):Kubernetes簡介
随机推荐
一种超参数优化技术-Hyperopt
Image processing toolkit imagexpresshow to view events
Dynamsoft barcode reader v7.5!
滴滴的分布式ID生成器(Tinyid),好用的一批
如何使用甘特图图层和筛选器
Implementation of nginx version of microservice architecture
南京标志设计,logo设计公司
Microservice - how to limit and fuse service current
失眠一个整晚上
Idea activation to 2089 failure
傲視Kubernetes(一):Kubernetes簡介
Win7 AppCrash (solution)
20 XR projects roadshows, nearly 20 capital institutions attended! We sincerely invite you to attend the 2020 qcomm XR eco Partner Conference
VARCHART XGantt入门教程
课堂练习
k-vim安装及The ycmd server SHUT DOWN (restart with ':YcmRestartServer')这种错误的解决方法
Reserved battery interface, built-in charge and discharge circuit and electricity meter, quickly help easily handle hand-held applications
How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
测试攻城狮必备技能点!一文带你解读DevOps下的测试技术
PHP backdoor hiding skills