I am trying to iterate through the body tag and all its children deep like if one of the children of the body contains other children, I want to be to reach those as well, I am trying to come up better and faster algorithm can anyone help to come up a better one other than mine?
<body>
<div class = "header-section">
<header class = "header-himself">
<div class = "nav-section">
<nav class = "nav-himself">
<div class = "list-section-left">
<ul class = "list-itself-left">
<li>Darster</li>
<li>Company</li>
<li>Safety</li>
<li>Help</li>
</ul>
</div>
<div class = "list-section-right">
<ul class="list-itself-right">
<li>Service</li>
<li>Dart In</li>
<li>Dart Out</li>
</ul>
</div>
</nav>
</div>
</header>
</div>
</body>
var target = document.querySelector('body');
function getChildren(target) {
if(target.children.length === 0) {
return;
}
for(var i = 0; i < target.children.length; i++) {
console.log(target.children[i].tagName);
getChildren(target.children[i]);
}
}
getChildren(target);