I have following Problem:
I have no clue how I let JavaScript delete a random Child.
I have a DIV
(gets randomly chosen). In this DIV
are more DIV
s and I want a JavaScript function that deletes one or two DIV
s. But there is one DIV
in there that shouldn't be deleted. For now I have this:
if (spieleranzahl == 4) {
var del = document.getElementById(random)
if(del.hasChildNodes()){
let rdm = Math.floor(Math.random() * 4);
del.removeChild(del.childNodes[rdm]);
}
if(del.hasChildNodes()){
let mdr = Math.floor(Math.random()* 3);
del.removeChild(del.childNodes[mdr]);
}
}
thanks for Answers.