title: Get the nodeValues of all parent elements of element?
body: <p>I have an HTML document, and it is structured thusly:</p>
  <pre><code>&lt;div id=&quot;oa2&quot;&gt;
      Content
      &lt;div&gt;
          Content
          &lt;div&gt;
          . . .
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>And the chain of elements may go arbitrarily deep. When there is a click on the screen, I pick it up and attempt to get the parental chain of custody for the clicked element using the following JavaScript:</p>
  <pre><code>let a=document.getElementById(&quot;oa2&quot;);
  let c=[];
  let d=[];
  let i=[0,0,0,0];
  document.onclick=function(e){
      let b=e.target;
      while(b){
          let f=b.childNodes;
          if(b==(a||document.body)){break;};
          if(!d.includes(b.id)){d[i[0]]=b.id;i[0]++;};
          while(i[3]&lt;f.length){
              if(f[i[3]].nodeType==Node.TEXT_NODE)
              {c[i[1]]=[];c[i[1]][i[3]]=f[i[3]].nodeValue};
              i[3]++;
          };
          b=b.parentElement;
      };
      i[1]++;
      i[3]=0;
  };
  </code></pre>
  <p>To be clear, what I want is an array (<code>c</code>) which contains arrays which contain the &quot;path&quot; of a child element's content and the content of each successive parent element's content. Every time there is a click on the document, I want a new child array in <code>c</code> holding the &quot;path&quot; of the clicked element, with out duplicates (I took care of that with <code>d</code>)..</p>