Every line of 'remove last child javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
58 removeChildrenExceptLast(node) { 59 if (node) { 60 while (node.childNodes.length > 1) { 61 node.removeChild(node.firstChild) 62 } 63 } 64 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
34 removeChild(child) { 35 const index = this.childNodes.indexOf(child); 36 if (index === -1) return; 37 child.parentNode = undefined; 38 this.childNodes.splice(index, 1); 39 40 const nextSibling = child.nextSibling; 41 if (child.previousSibling) { 42 child.previousSibling = nextSibling; 43 } 44 45 child.nextSibling = child.previousSibling = undefined; 46 }
23 function remove(child) { 24 if(Array.isArray(child)) { 25 let currentChild = child[0], 26 nextChild; 27 const lastChild = child[1], 28 parent = lastChild.parentNode; 29 30 while(currentChild !== lastChild) { 31 nextChild = currentChild.nextSibling; 32 parent.removeChild(currentChild); 33 currentChild = nextChild; 34 } 35 36 parent.removeChild(lastChild); 37 } 38 else { 39 child.parentNode.removeChild(child); 40 } 41 }