For example, in the structure below I have a div
that has a text and another div
that also has text. How can I capture or check if a text is a child direct from a tag, not a child of another child tag:
console.log(document.querySelector('.div1').textContent)
.div1{
background: #ccc;
padding: 10px
}
.div2{
background: #999;
padding: 10px
}
<div class="div1">
Texto filho direto da div1
<div class="div2">
Texto filho direto da div2 e filho indireto da div1
</div>
</div>