Javascript remove all child elements
// Get the <ul> element with id="myList"
let list = document.getElementById("myList");
// As long as <ul> has a child node, remove it
while (list.hasChildNodes()) {
list.removeChild(list.firstChild);
}var myDiv = document.getElementById("myDivID");
myDiv.innerHTML = "";//remove all child elements inside of myDivfunction deleteChild() {
let e = document.querySelector("ul");
//e.firstElementChild can be used.
let child = e.lastElementChild;
while (child) {
e.removeChild(child);
child = e.lastElementChild;
}
}
let btn = document.getElementById(
"btn").onclick = function() {
deleteChild();
} document.getElementById("myDivID").innerHTML = "";
Also in JavaScript:
- sort by string react
- set attribute javascript
- jquery cheat sheet
- antiforgerytoken mvc with ajax
- how to use media queries in emotion
- webslesson search bar ajax
- jquery append before
- angular two way property binding
- sample of jstree ajax call code farm
- string literals javascript
- bootstrap 3 min max price range slider
- jquery loop through list element
- javascript array to csv string
- max value in array javascript
- json-server localhost
- let javascript
- calculate two number and diplay next field without reload the page javascript
- how to delete element in list javascript
- angular 9 release date
- react background image
- javascript get dictionary values
- string to date angular
- javascript pareseint
- react image upload