Javascript remove node removeChild of use introduction

  • 2020-03-30 02:30:33
  • OfStack

RemoveChild (a) is used to remove existing elements from a document
Parameter a: the node to be moved out
<div id="guoDiv"> 

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

Related articles: