Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72416

How to choose random children

$
0
0

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 DIVs and I want a JavaScript function that deletes one or two DIVs. 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.


Viewing all articles
Browse latest Browse all 72416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>