Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will need to do something like the following (recursive cross-browser)</p> <p>Javascript</p> <pre><code>function walkTheDOM(node, func) { func(node); node = node.firstChild; while (node) { walkTheDOM(node, func); node = node.nextSibling; } } function textNodeValuesToArray(node) { if (typeof node === "string") { node = document.getElementById(node); } var arrayOfText = []; function pushText(currentNode) { if (currentNode.nodeType === 3) { arrayOfText.push(currentNode.nodeValue); } } walkTheDOM(node, pushText); return arrayOfText; } console.log(textNodeValuesToArray("parentfolder")); </code></pre> <p>On <a href="http://jsfiddle.net/Xotic750/j28u6/" rel="noreferrer">jsfiddle</a></p> <p>Or using <a href="https://developer.mozilla.org/en-US/docs/Web/API/treeWalker" rel="noreferrer"><code>treewalker</code></a></p> <blockquote> <p><strong>Browser compatibility</strong></p> <p>Supported by IE9+, FF2+, Chrome 1+, Safari 3+, Opera 9+</p> </blockquote> <p>Javascript</p> <pre><code>function textNodeValuesToArray(node) { if (typeof node === "string") { node = document.getElementById(node); } var arrayOfText = [], treeWalker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, { acceptNode: function (node) { return NodeFilter.FILTER_ACCEPT; } }, false); while (treeWalker.nextNode()) { arrayOfText.push(treeWalker.currentNode.nodeValue); } return arrayOfText; } console.log(textNodeValuesToArray("parentfolder")); </code></pre> <p>On <a href="http://jsfiddle.net/Xotic750/a5zPQ/" rel="noreferrer">jsfiddle</a></p> <p>Without recursion and cross browser would be something like this</p> <p>Javascript</p> <blockquote> <p><strong>Avoid using labels</strong></p> <p>Labels are not very commonly used in JavaScript since they make programs harder to read and understand. As much as possible, avoid using labels and, depending on the cases, prefer calling functions or throwing an error.</p> </blockquote> <pre><code>function walkDOM(root, func) { var node = root; start: while (node) { func(node); if (node.firstChild) { node = node.firstChild; continue start; } while (node) { if (node === root) { break start; } if (node.nextSibling) { node = node.nextSibling; continue start; } node = node.parentNode; } } } function textNodeValuesToArray(node) { if (typeof node === "string") { node = document.getElementById(node); } var arrayOfText = []; function pushText(currentNode) { if (currentNode.nodeType === 3) { arrayOfText.push(currentNode.nodeValue); } } walkDOM(node, pushText); return arrayOfText; } console.log(textNodeValuesToArray("parentfolder")); </code></pre> <p>On <a href="http://jsfiddle.net/Xotic750/ufpwT/" rel="noreferrer">jsfiddle</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload