title: Get parent element of nested child by class or name
body: <p>I have html elements like follows with <em>unknown</em> hierarchy: </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="parent" name="parent"&gt;
    &lt;div&gt;
      &lt;div&gt;
        &lt;div&gt;
          &lt;div onclick="get_parent(this)"&gt;
            Nested Child 1
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="parent" name="parent"&gt;
    &lt;div&gt;
      &lt;div onclick="get_parent(this)"&gt;
        Nested Child 2
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Is there any easy way to get parent of nested child by class or name? </p>
  
  <p>Maybe there is some alternative to <code>child.parentElement</code> or <code>child.parentNode</code> I am not aware of which may help me? </p>
  
  <p>Or looping through all parents until I get needed <code>class</code> or <code>name</code> is the only possible choice?</p>