showing results for - "js find all text elements"
Meryem
22 May 2016
1function textNodesUnder(el){
2  var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
3  while(n=walk.nextNode()) a.push(n);
4  return a;
5}
6
Manuel
17 Jun 2018
1function textNodesUnder(node){
2  var all = [];
3  for (node=node.firstChild;node;node=node.nextSibling){
4    if (node.nodeType==3) all.push(node);
5    else all = all.concat(textNodesUnder(node));
6  }
7  return all;
8}
9