How can I find out the total children count of each root node P in my JSON object. This is not a DOM structure. Considering P2 's children also children of P1 as P2 is child of P1.
P1-|-C1 (P1 children count 3)
|-C2
|-P2-|-C1 (P2 children count 5)
|-C2
|-P3-|-C1 (P3 children count 2)
|-C2
|-C3
|-C4
|-P4-|-C1 (P4 children count 2)
|-C2
Thanks in advance.
It's fairly simple without any library or custom code.
//Or whatever way you want to grab a reference to the DOM node
var p1 = document.getElementById('P1');
p1.getElementsByTagName('*').length
Maybe I misunderstood the question. Is this what you want?:
p1.childNodes.length
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With