var el = document.getElementById("parentDiv");
console.log(el.textContent);
console.log(el.innerText);
console.log(el.innerHTML);
<div id="parentDiv">
parent div
<p>p</p>
<div>
this text is in a div
<span>span</span>
<a>im a link!</a>
<div>
another div
<div>
<span><a>link in a span</a></span>
</div>
</div>
</div>
</div>
When running this, it always returns 'parent div' plus all the text from the child elements. Is there a way to only return 'parent div' using js?