Let's say I have the following element TEXT
in HTML:
<div id="TEXT">
<p>First <strong>Line</strong></p>
<p>Seond <em>Line</em></p>
</div>
How should one extract the raw text from this element, without HTML tags, but preserving the line breaks?
I know about the following two options but neither of them seems to be perfect:
document.getElementById("TEXT").textContent
- returns
First LineSecond Line
- problem: ignores the line break that should be included between paragraphs
- returns
document.getElementById("TEXT").innerText
- returns
First Line Second Line
- problem: is not part of W3C standard and is not guaranteed to work in all browsers
- returns