JSFiddle - React, Tailwind, and code Playground
by sandro_paganotti
HTML
<div id="trajeto-texto1">
<span id="resultado">
<div class="calculo"><label>Distância: 0.00 Km</label></div>
<div class="calculo"><label>Duração: 0 min.</label></div>
<div class="calculo"><label>Custo: R$ 0,00</label></div>
</span>
</div>
JavaScript
function getTexts(rootNode){
var stack = Array.prototype.slice.call(rootNode.childNodes,0);
var texts = [];
var currentNode;
while(currentNode = stack.pop()){
if(currentNode.nodeType === Node.TEXT_NODE &&
currentNode.textContent.match(/[A-z0-9]/)
){
texts.push(currentNode.textContent);
}
if(currentNode.childNodes.length > 0){
stack.push.apply(stack,
Array.prototype.slice.call(currentNode.childNodes,0)
);
}
}
return texts;
};
console.log(getTexts(document.getElementById('trajeto-texto1')));