码迷,mamicode.com
首页 > 其他好文 > 详细

添加和删除节点

时间:2017-12-08 18:22:50      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:app   before   child   script   rip   元素   lang   append   utf-8   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加和删除节点</title>
</head>
<body>
<div id="div1">
<p id="p1">这是一个段落</p>
<p id="p2">这是第二个段落</p>
</div>
<script>
var para = document.createElement(‘p‘);
var node = document.createTextNode(‘这是我又创建的另一个新元素‘);
para.appendChild(node);
var element = document.getElementById(‘div1‘);
var child = document.getElementById(‘p2‘);
// element.appendChild(para);
element.insertBefore(para,child);
element.removeChild(child);
</script>
</body>
</html>

添加和删除节点

标签:app   before   child   script   rip   元素   lang   append   utf-8   

原文地址:http://www.cnblogs.com/studyh5/p/8006341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!