当前位置:网站首页>DOM - node operation
DOM - node operation
2022-07-23 05:14:00 【m0_ sixty-two million one hundred and sixty-eight thousand and 】

Node properties
The attribute name describe
parentNode Return the parent of the node
childNodes Returns the collection of child nodes ,childNodes[i], Including line breaking text nodes and comments
firstChild Returns the first child of the node , The most common use is to access the text node of the element
lastChild Returns the last child of the node ,
nextSibling Next node
previousSibling Last node
nextSibling、previousSibling Only nodes of the same level can be selected , Cannot be transferred to parent

Example :

Element attribute
The attribute name describe
firstElementChild Returns the first child of the node
lastElementChild Returns the last child of the node
nextElementSibling Next node
previousElementSibling Last node
How to be compatible with Google and ie8 And the following browser :
In Google browser and ie9 And above , Use firstChild 、lastChild、nextSibling 、previousSibling It contains text nodes , But while Ie8 And the following , No text nodes ( Statement let stay ie China does not support it. )
ie8 And the following browsers do not contain text nodes ; however ie8 The comment will be selected as a node , and ie7 and ie5 Comments are not selected as element nodes
|| Next is written to ie8 And the following browsers , because ie8 I won't support it nextSibling etc. ....
ie8 When you encounter comments, you will treat comments as elements ;
oNext = oParent.nextElementSibling || oParent.nextSibling
oPre = oParent.previousElementSibling || oParent.previousSibling
oFirst = oParent. firstElementChild || oParent.firstChild
oLast = oParent.lastElementChild || oParent.lastChild

Node information
nodeName: The name of the node #text( Text nodes include line breaks and spaces )、 Capitalized element names 、comment notes
nodeValue: Node values “\n ” ,"null"," I am a comment "
nodeType: Node type 3, 1, 8
Node type NodeType value
Elements element 1
Text text 3
notes comments 8
file document 9
console.log(document.nodeType)=9;

Set properties
setAttribute() Method to add the specified property , And assign it a specified value , Add existing attributes and custom attribute values
attributename The name of the added attribute
attributevalue Added attribute value
element.setAttribute(“attributename”,“attributevalue”)
example :document.getElementById("a").setAttribute("src","image/b.jpg");
get attribute
getAttribute() Method returns the property value of the specified property name
attributename It's necessary . You need to get the attribute name of the attribute value
element.getAttribute(“attributename”)
Delete attribute
removeAttribute() Method to delete the specified attribute
attributename Name of the removed attribute
element.removeAttribute(attributename)
document.getElementById("a").removeAttribute("src");

边栏推荐
- Netlist simulation introduce
- 数字孪生示范项目——从单摆谈起(4)IoT探索
- Druid源码阅读7-DruidDataSource的recycle过程
- A new look at linear classifiers from a geometric perspective
- makefile 使用简介
- Methods and steps of packaging a uniapp project as a desktop application
- 正则表达式常用的限定符&&Cookie
- Escape (bipartite multiple matching)
- Deep learning series -- alxenet realizes MNIST handwritten numeral recognition
- 语义SLAM开山之作:Probabilistic Data Association for Semantic SLAM 语义slam的概率数据关联
猜你喜欢

Tensorflow for MNIST handwritten numeral recognition

Deep learning series -- alxenet realizes MNIST handwritten numeral recognition

Druid源码阅读2-DruidDataSource的init过程

Game between linear classifiers of linear model

The remote warehouse is pulled successfully, and the folder of the local warehouse still displays a red exclamation point

A new look at linear classifiers from a geometric perspective

On GaN Network - II

合工大苍穹战队视觉组培训Day1——机器学习,学会使用YOLO模型

SVM To Face Recognize

感知机与多层神经网络,反向传播与计算图
随机推荐
Arm V8 program guide - Chapter 10 aarch64 exception handling (translation)
正则表达式常用的限定符&&Cookie
数字孪生示范项目——从单摆谈起(3)实体模型探索
Espressif 玩转 WebSocket
*Environment configuration *win10 test after installing CUDA, cudnn, pytorch GPU, tensorflow GPU
verilog 避坑指南(持续更新)
EOJ monthly 2021.2 sponsored by tusimple a
Escape (bipartite multiple matching)
*Precision optimization * optimization strategy 1: network +sam optimizer
SV知识点总结
51nod 2840 ATM (tarjan, shrink point, DFS)
GIC Introduction (II) - use of gic400
Druid源码阅读5-DruidDataSource的shrink过程
智能机器人与智能系统(大连理工大学庄严教授)——2.移动机器人感知
Détails du Protocole Axi
Nodejs implements scheduled tasks
ICM20948九轴传感器角速度读取与实际单位转化的换算关系
HDU 2167 pebbles (state compression)
nodejs实现定时任务
The remote warehouse is pulled successfully, and the folder of the local warehouse still displays a red exclamation point