
When watching the tutorial the teacher said that html was a child node of DOCUMENT, but said the text "jQuery Adventures" was "under" the title node.
So is the text within an element is technically a child node of that element or does it just appear under it in the DOM? Does it ever matter when coding?
Yes, a contiguous run of text inside an element becomes a text node which is a child of that element.
var el = document.querySelector('div');
console.log(el.childNodes.length); // 1 child node
console.log(el.childNodes[0].nodeType === Node.TEXT_NODE); // text node
console.log(el.childNodes[0].nodeValue); // text contents
<div>Hello</div>
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