当前位置:网站首页>DOM add
DOM add
2022-07-22 19:29:00 【Please call me Gerald 6】
document.createElement()
Can be used to create an element node object , It requires a tag name as a parameter , The element node object... Will be created based on the tag name , And return the created object as the return value
eg: Create a li
var li = document.createElement("li");
document.createTextNode()
Can be used to create a text node object You need a text content as a parameter , A text node will be created based on this content , And return the new node to
eg: Create Guangzhou text node
var gzText = document.createTextNode(" Guangzhou ");
appendChild()
Add a new node to a parent node
eg: take gzText Set to li Child nodes of
li.appendChild(gzText);
insertBefore()
You can insert a new child node before the specified child node
grammar : Parent node .insertBefore( New node , Old node )
eg: On the parent node city Next , stay bj Insert a before li
city.insertBefore(li ,bj);
replaceChild()
You can replace an existing child node with a specified child node
grammar : Parent node .replaceChild( New node , Old node )
eg: Use li Replace bj
city.replaceChild(li ,bj);
removeChild()
Delete a child node
grammar : Parent node .removeChild( Child node )
eg: Delete bj
city.removeChild(bj);
Be careful 1: In fact, many times we don't know who the parent node is , Then you can use the following method
bj.parentNode.removeChild(bj);
Be careful ·2: Use innerHTML It can also be done DOM Add, delete and change operations , Generally, we will use a combination of two ways
// Create a li
var li = document.createElement("li");
// towards li Set text in
li.innerHTML = " Guangzhou " ;
// take li Add to city in
city.appendChild(li);
边栏推荐
- LeetCode 每日一题 2021/12/13-2021/12/19
- [FatFs] porting FatFs file system based on STM32 SD card
- 4G工业路由器大气环境监测方案
- grafana面板-关于转换
- 助力品牌洞察——消费者情绪行为分析
- “35岁,我退休了”:关于中年危机,这是最靠谱的回答
- Leetcode daily question 2021/12/13-2021/12/19
- Future prospects and trends of IT outsourcing service industry in various fields
- grafana面板-覆盖字段值
- LeetCode 每日一题 2022/3/28-2022/4/3
猜你喜欢
grafana面板-覆盖字段值
“35岁,我退休了”:关于中年危机,这是最靠谱的回答
Mysql5.7 decompression configuration steps
MFC dialog program only runs a simple example of a single instance
Oracle容器数据库的安装和使用
Enumerate properties in objects
experience""/>
Renjie, chief scientist of rongyun: experience produces talents, and career "experience > experience"
Server disk IO performance tuning
Writing word accumulation
Flutter's first program Hello world!
随机推荐
Flutter's first program Hello world!
什么是“实时”
Leetcode daily question 2021/12/13-2021/12/19
Help brand insight -- Analysis of consumers' emotional behavior
Future prospects and trends of IT outsourcing service industry in various fields
Shell script debugging technology
Enumerate properties in objects
Atmospheric environment monitoring scheme for 4G industrial router
不再执着于用产品说话,苹果库克加大美国反垄断游说投入:今年上半年支出 460 万美元
协同办公市场暴增背后:融云通信能力是需求重点
LeetCode 每日一题 2021/12/6-2021/12/12
2022 centos8 Yum image installation & Alibaba cloud MySQL 5.7 tutorial and problem solving
Leetcode daily question 2022/3/14-2022/3/20
Leetcode: 185. all employees with the top three highest wages in the Department
MNIST handwritten numeral recognition case tensorflow 2.0 practice
LeetCode 每日一题 2022/1/3-2022/1/9
Sorting of in-depth learning materials
JUC synchronizer
2、 Idea build jfinal project + automatic code generation + database operation test (three ways)
Oracle容器数据库的安装和使用