JSFiddle - React, Tailwind, and code Playground

HTML

<h1>Header</h1>
<p>Paragraph</p>
<ul>
    <li>First</li>
    <li>Second</li>
</ul>
<dl>
    <dt>Term</dt>
        <dd>Definition</dd>
</dl>
<div>Div with <span>span</span>.<br />After the <a href="...">break</a>.</div>

JavaScript

function getText($node) {
    return $node.contents().map(function () {
        if (this.nodeName === 'BR') {
            return '\n';
        } else if (this.nodeType === 3) {
            return this.nodeValue;
        } else {
            return getText($(this));
        }
    }).get().join('');
}
alert(getText($('body')));