Get text inside parent div
I am trying to get text from an element that is not the first parent of the string. i.e.
<div id="wrp">
<h1>
<a href="www.something.com">this is the text I want</a>
</h1>
</div>
let's say I got the parent div element=document.getElementById("wrap"), and now I want to get its final text without looking at its children: h1and a. just the text that I see on the site.
Is it possible? Please show me an example.
+4
2 answers
You can use both innerText, and textContent, but innerText does not work in Firefox . So, the solution of the crossbrowser:
var text = element.innerText || element.textContent;
+1