JSFiddle - React, Tailwind, and code Playground
by Derek Leung
HTML
<div class="no-text example">100</div>
<div class="with-text example"><span class="surprise"> 50 </span>
100</div>
JavaScript
$(".example")
.contents()
.filter(function () {
return this.nodeType === 3; //Node.TEXT_NODE
}).each(function () {
window.a= this;
console.log("text node: ", +this.nodeValue.trim());
});