JSFiddle - React, Tailwind, and code Playground

by Tonio Loewald

HTML

<p>
    This is a test
    <b>So is<span class="c1"></span> this</b>
    And this
    <blockquote>
        And then
        <i>There <span class="c2"></span>is</i>
        this
    </blockquote>
    And some more here
    <i>and here</i>
    Then <span class="c3"></span>here
</p>

JavaScript

var p = document.querySelector('p');

function allText(node){
    nodeList = [];
    for(var i = 0; i < node.childNodes.length; i++){
        console.log(node.childNodes[i]);
        nodeList.push(node.childNodes[i]);
        if(node.childNodes[i].firstChild){
            nodeList = nodeList.concat( allText(node.childNodes[i]) );
        }
    }
    return nodeList;
}

console.log(allText(p));