Home > Web Front-end > JS Tutorial > Introduction to using removeChild() to remove a node using javascript_javascript skills

Introduction to using removeChild() to remove a node using javascript_javascript skills

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

removeChild(a) is used to delete existing elements in the document
Parameter a: the node to be removed

Copy code The code is as follows:


1
2
< ;span>3


var oDiv = document.getElementById("guoDiv");
var firsChild = oDiv.firstElementChild ? oDiv.firstElementChild : oDiv. firstChild
var returnNode = oDiv.removeChild(firsChild); //Remove the first element and return the removed element
alert(returnNode.innerHTML); //1
var lastChild = oDiv.lastElementChild ? oDiv .lastElementChild : oDiv.lastChild;
returnNode = oDiv.removeChild(lastChild); //Remove the last element and return the removed element
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template