当前位置:网站首页>JS find all nodes sibling childNodes children
JS find all nodes sibling childNodes children
2022-07-27 19:51:00 【HandsomeDanielWu】
siblings Brothers and sisters





childNodes Unique child nodes 
Place the space <div/> Text node <p><p/><div>
children




Find all nodes 







![]()




encapsulation , Return all element sibling nodes
<body>
<div class="box">
<p> I'm a paragraph </p>
<p> I'm a paragraph </p>
<p> I'm a paragraph </p>
<p id="fpara"> I'm a paragraph </p>
I am the text
<!-- I am a comment -->
<p id="para">
I'm a paragraph para
<span>1</span>
<span>2</span>
<span>3</span>
</p>
<p> I'm a paragraph </p>
<p> I'm a paragraph </p>
<p> I'm a paragraph </p>
</div>
<script>
var box = document.getElementById("box");
var para = document.getElementById("para");
var fpara = document.getElementById("fpara");
// encapsulation , Return all element sibling nodes
function getAllElementSiblings(node){
// Brother node in front
var prevs = [];
// Brother nodes behind
var nexts = [];
var o = node;
// facilitate Node The front node
while(o.previousSibling != null){
if(o.previousSibling.nodeType == 1){
prevs.unshift(o.previousSibling);
}
o = o.previousSibling ;
}
o = node;
// facilitate Node Back node
while(o.nextSibling != null){
if(o.nextSibling.nodeType == 1){
nexts.push(o.nextSibling);
}
o = o.nextSibling;
}
//prevs Array merge nexts Array
return prevs.concat(nexts);
}
console.log(getAllElementSiblings(para));
</script>
</body>边栏推荐
- [basic knowledge of deep learning - 39] comparison of BN, LN and WN
- IEC104 规约详细解读(一) 协议结构
- Surpass Huawei? Ericsson has won more than 75 5g commercial contracts
- jvisualvm的使用
- JVM概述和内存管理(未完待续)
- Release Samsung 3J1 sensor: the code implies that the safety of pixel 7 face recognition will be greatly increased
- 【深度学习基础知识 - 44】逻辑回归实现多分类的方法
- [basic knowledge of deep learning - 46] Bayesian theorem and conditional probability formula
- 台积电5nm即将量产:苹果A14独占7成产能,华为麒麟1020拿下3成
- SystemService(系统服务)
猜你喜欢
Dry goods of technical practice | preliminary exploration of large-scale gbdt training

【深度学习基础知识 - 45】机器学习中常用的距离计算方法

AutoCompleteTextView(输入框预匹配)

访问控制

【深度学习基础知识 - 43】优势比的概念

RadioGroup(单选框)

Oracle XE版安装与用户操作

Binary search tree

GestureDetector(手势识别)

5W bonus pool / for colleges and universities, 2022 legal science and technology innovation competition is in progress
随机推荐
Make your chat bubbles colorful
The valuation exceeds 15.6 billion yuan! Huaqin communication completed the round B financing of 1billion yuan! Qualcomm venture capital, Intel Capital led investment
Pytorch reports CUDA error: no kernel image is available for execution on the device error
【深度学习目标检测系列 - 01】目标检测是什么
[basic knowledge of deep learning - 46] Bayesian theorem and conditional probability formula
台积电5nm即将量产:苹果A14独占7成产能,华为麒麟1020拿下3成
[basic knowledge of deep learning - 41] quick start learning materials for deep learning
SumMenuDemo(子菜单)
【深度学习基础知识 - 44】逻辑回归实现多分类的方法
嵌入式C语言结构体
JS 事件监听 鼠标 键盘 表单 页面 onclick onkeydown onChange
What's new in helix QAC 2022.2, the ace code static testing tool (1)
Uncover the mystery of Qualcomm ultrasonic fingerprint being "cracked by film"
英特尔未来10年工艺路线图曝光:2029年推出1.4nm工艺!如何实现?
[deep learning target detection series - 01] what is target detection
SQlife(数据库)
rxbinding
[basic knowledge of deep learning - 43] concept of odds ratio
[basic knowledge of deep learning - 44] the method of realizing multiple classification by logistic regression
Introduction to Flink operator