How to operate JS to dynamically add and delete tags

php中世界最好的语言
Release: 2018-06-07 14:26:03
Original
4227 people have browsed it

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

Copy after login

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); }
Copy after login

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   
  

Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!