当前位置:网站首页>DOM 节点
DOM 节点
2022-06-21 23:23:00 【InfoQ】
DOM 节点
节点操作
获取节点
公共html部分
<div id="box" class="abc" index="hello world">
hello
<p>你好</p>
wolrd
<p>世界</p>
</div>
获取元素
var div = document.querySelector('div') var child = div.childNodes;
console.log(child); var childEle = div.children;
console.log(childEle); var first = div.firstChild;
console.log(first);var firstEle = div.firstElementChild;
console.log(firstEle); var last = div.lastChild;
console.log(last);var lastEle = div.lastElementChild;
console.log(lastEle); var prev = div.previousSibling;
console.log(prev);var prevEle = div.previousElementSibling;
console.log(prevEle);var next = div.nextSibling;
console.log(next);var nextEle = div.nextElementSibling;
console.log(nextEle);var parent = div.parentNode;
console.log(parent);var parentEle = div.parentElement;
console.log(parentEle); var attrs = div.attributes;
console.log(attrs);节点属性
1. nodeType
2. nodeName
3. nodeValue
// 元素节点
var div = document.querySelector('div')
// 属性节点
var attr = div.attributes[0]
// 文本节点
var text = div.childNodes[2]
// 注释节点
var comment = div.childNodes[1]
console.log('元素节点 ', div)
console.log('属性节点 ', attr)
console.log('文本节点 ', text)
console.log('注释节点 ', comment)
console.log('===========================')
// 节点属性 - 节点的值
console.log('元素节点 ', div.nodeValue)
console.log('属性节点 ', attr.nodeValue)
console.log('文本节点 ', text.nodeValue)
console.log('注释节点 ', comment.nodeValue)边栏推荐
- [node] node uses MySQL connection pool
- 【愚公系列】2022年06月 通用职责分配原则(九)-受保护变量原则
- 【taro】taro微信小程序input在苹果手机上光标聚焦不对的解决办法
- Pseudo instruction in arm assembly
- 数学知识:约数个数—约数
- Katalon framework test web (VIII) wait
- JSONObject获取Date类型(getSqlDate)报错
- 【2023提前批 之 面经】~ 青岛鼎信科技
- 8 种最坑SQL语法,工作中踩过吗?
- Mathematical knowledge: greatest common divisor divisor
猜你喜欢

buuctf misc 间谍启示录
![Shenzhen Data Analyst Certification (CPDA) in the second half of 2022, [enter to view]](/img/9a/4fe513a71f5efc7cce318708d6931e.jpg)
Shenzhen Data Analyst Certification (CPDA) in the second half of 2022, [enter to view]
![Xshell can only input the public key solution [personal test] when connecting to the virtual machine](/img/a9/2c315f92cef46976353b52fb1d0fba.png)
Xshell can only input the public key solution [personal test] when connecting to the virtual machine

数据治理的重要性

Buuctf misc Xiaoyi USB flash disk

HMS core machine learning service ID card identification function to achieve efficient information entry

Document.readyState 如何使用和侦听

Qt之自制MP3播放器

Buuctf misc spy Apocalypse

Meet webassembly again
随机推荐
关于相机位姿的可视化
[PHP] MVCs concept (easy to understand)
Katalon框架测试web(八)等待
【typescript】typscript中感叹号和问号的区别
Introduction to some code static checking tools
再次认识 WebAssembly
If a programmer goes to prison, will he be assigned to write code?
【php】mvcs概念(通俗易懂)
[sword finger offer] 43 Number of occurrences of 1 in integers 1 to n
Client construction and Optimization Practice
Continuous integration of metersphere and Jenkins
Introduction to activities in the name of the father (you can collect sheep)
We sincerely invite elastic stack developers to become CSDN elastic cloud community administrators
leetcode 279. Perfect squares (medium)
[RoarCTF2019]黄金6年
唐太宗把微服务的“心跳机制”玩到了极致!
数学知识:约数之和—约数
Im instant messaging source code + software +app with detailed package video building tutorial
Thinking about a web offline interview
Farm Game