当前位置:网站首页>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>边栏推荐
- View pagoda PHP extension directory
- VS2017#include 'xxx.h'
- JVM概述和内存管理(未完待续)
- Flink简介以及运行架构
- 【深度学习基础知识 - 50】PCA降维 主成成分分析
- SharePreference(存储)
- Hdu1573 x problem [univariate linear congruence equations]
- Oracle 简单的高级查询
- [basic knowledge of deep learning - 48] characteristics of Bayesian network
- Pytorch reports CUDA error: no kernel image is available for execution on the device error
猜你喜欢

Hyperledger caliper is built on fabric for performance test

ToggleButton(按钮开关)

Oracle +JDBC

Map和Set

High cost, difficult to implement, slow to take effect, what about open source security?
![[RCTF2015]EasySQL-1|SQL注入](/img/69/aa1fc60ecf9a0702d35d876e8c3dda.png)
[RCTF2015]EasySQL-1|SQL注入

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

Application pool has been disabled

Oracle XE版安装与用户操作

Influxdb series (IV) TSM engine (storage principle)
随机推荐
【深度学习基础知识 - 42】逻辑回归详解
Chinese character search Pinyin wechat applet project source code
Hdu1573 x problem [univariate linear congruence equations]
[Huawei cloud stack] [shelf presence] issue 13: have you seen the decoupling architecture of the management area? Help government and enterprise customers solve big problems
下放三星3J1传感器:代码暗示Pixel 7人脸识别安全性将大增
【日常积累 - 06】查看cuda和cudnn版本
Map和Set
【深度学习基础知识 - 50】PCA降维 主成成分分析
嵌入式C语言对次数固定的循环的优化
ReferenceError: __ dirname is not defined in ES module scope
二叉搜索树
[deep learning target detection series - 01] what is target detection
Flink 算子简介
TSMC 5nm is about to mass produce: Apple A14 monopolizes 70% of the production capacity, and Huawei Kirin 1020 takes 30%
AutoCompleteTextView(输入框预匹配)
BroadcastReceiver(广播)
FileOutputStream(文件储存)与FileInputStream(文件读取)
一种比读写锁更快的锁,还不赶紧认识一下
【深度学习基础知识 - 40】CNN为什么比DNN在图像领域更具优势
【深度学习基础知识 - 49】Kmeans