3
For example, in the structure below I have a div
that has a text and another div
which also has a text. How can I capture or verify if a text is the direct son of a tag, and not the son of another daughter 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>