ChildNodes возвращает только первого потомка, как получить массив всех вложенных нодов родителя? javascript
const div = document.createElement("div");
const p = document.createElement("p");
const span = document.createElement("span");
p.appendChild(span);
div.appendChild(p);
nodeChildCount(div); // 2
//nodeChildCount(div, 1); // 1
//nodeChildCount(div, 2); // 2
function nodeChildCount(element, deep) {
if(element.hasChildNodes()) {
var children = element.childNodes;
console.log(children.length) // 1
}
}