当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
- [original] the impact of arm platform memory and cache on the real-time performance of xenomai
- 廬山真面目之二微服務架構NGINX版本實現
- Git SSH bad permissions
- 三步轻松理解Kerberos协议
- Design pattern of facade and mediator
- 11. Service update
- Using rabbitmq to implement distributed transaction
- Three steps to understand Kerberos Protocol easily
- C語言重點——指標篇(一文讓你完全搞懂指標)| 從記憶體理解指標 | 指標完全解析
猜你喜欢
Solution to st link USB communication error in stlink Download
HMS core push service helps e-commerce app to carry out refined operation
JS string - string string object method
win7如何快速打cmd并到达所要的目录
9. Routingmesh service communication between clusters
Git SSH bad permissions
How to solve the problem of blank page in Google Chrome browser
Opencv computer vision learning (10) -- image transform (Fourier transform, high pass filter, low pass filter)
In simple terms, the large front-end framework angular6 practical course (angular6 node.js 、keystonejs、
测试攻城狮必备技能点!一文带你解读DevOps下的测试技术
随机推荐
如何使用甘特图图层和筛选器
Git SSH bad permissions
Dynamsoft barcode reader v7.5!
11. Service update
如何创建交互式内核密度图表
快進來!花幾分鐘看一下 ReentrantReadWriteLock 的原理!
课堂练习
python3操作Jenkins模块api
VARCHART XGantt入门教程
8.Swarm创建维护和水平扩展Service
Practice of Xiaoxiong school development board: real equipment access of smart street lamp sandbox experiment
Logo design company, Nanjing
VARCHART XGantt如何在日历上表示工作日
南京标志设计,logo设计公司
How to use Gantt chart layers and filters
Exclusive interview with alicloud database of | 2020 PostgreSQL Asia Conference: Wang Xu
使用RabbitMQ实现分布式事务
Python 3 operates the Jenkins module API
JS array the usage of array is all here (array method reconstruction, array traversal, array de duplication, array judgment and conversion)
Windows 10 Bluetooth management page 'add Bluetooth or other devices' option click no response solution