This time I will show you how to operate JS to dynamically add and delete tags, and what are the precautions for how to operate JS to dynamically add and delete tags. The following is a practical case, let's take a look.
1.p tag
1
2.js
function myFun9() { var mp3 = document.getElementById("mp3"); //获取组件1 var eleme = document.createElement("p"); //创建组件2 var ele_content = document.createTextNode("2");//创建节点内容 eleme.appendChild(ele_content); // 组件添加节点 mp3.appendChild(eleme); //组件2加入组件1 } ==================删除==============================
1
2
3
4
5
function myFun10(){ var parent=document.getElementById("mp4"); var son=document.getElementById("p1"); parent.removeChild(son); }
Supplement:
Let’s take a look at js-dynamically generated small dots (dynamically generated small dots based on the number of carousel images)
Dynamicly generate small dots (dynamically generate small dots based on the number of carousel images)
Document
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
How to sort json objects and delete data with the same id
How to use js to implement drag and drop function
The above is the detailed content of How to operate JS to dynamically add and delete tags. For more information, please follow other related articles on the PHP Chinese website!