JSFiddle - React, Tailwind, and code Playground
HTML
<span id="outer">
|first text|
<span>|second text|</span>
|third text|
</span>
<br/>
<br/>
<span id="output"></span>
JavaScript
var all = $('#outer').find('*').andSelf().contents();
$('#output').text(all.text());