javascript移出节点removeChild()使用介绍_javascript技巧

WBOY
Release: 2016-05-16 16:53:25
Original
1196 people have browsed it

removeChild(a)是用来删除文档中的已有元素
参数a:要移出的节点

复制代码代码如下:


1
2
3


var oDiv = document.getElementById("guoDiv");
var firsChild = oDiv.firstElementChild ? oDiv.firstElementChild : oDiv.firstChild
var returnNode = oDiv.removeChild(firsChild); //移出第一个元素,返回被移出元素
alert(returnNode.innerHTML); //1
var lastChild = oDiv.lastElementChild ? oDiv.lastElementChild : oDiv.lastChild;
returnNode = oDiv.removeChild(lastChild); //移出第后一个元素,返回被移出元素
alert(returnNode.innerHTML);//3
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!