title: Alternative to .parentElement?
body: <p>I have a function that needs to go through alot of <code>parentElement</code>s to get an id. Instead of writing <code>if( element.parentElement.parentElement.parentElement.id == "target" ){ doThis() }</code> Is there a way in javascript just to say "If there is a parent element with "this id" doThis()" ? Instead of going through all those parentElements is there a way to just say if there is ANY element that is a parent to the current element with this ID, then doThis()? </p>
  
  <p><strong>EDIT</strong> </p>
  
  <p>Many have said i should just <code>getElementById</code> and maybe that is the solution, but let me show you a example of my code so you can see a little better what I'm doing:</p>
  
  <p>I have alot of divs with the same function. lets call it clicked().</p>
  
  <p>so say i have 20 divs that look like this: <code>&lt;div onclick = "clicked( this )"&gt;Content&lt;/div&gt;</code></p>
  
  <p>Lets say these divs are contained within a few other divs:</p>
  
  <pre><code>&lt;div id = "container"&gt;
      &lt;div id = "top"&gt;
         &lt;div id = "left"&gt;
             &lt;div onclick = "clicked( this )"&gt;Content&lt;/div&gt;
             &lt;div onclick = "clicked( this )"&gt;Content2&lt;/div&gt;
             ...
         &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;  
  </code></pre>
  
  <p>my clicked function looks like:</p>
  
  <pre><code>function clicked( element ){
      if( element.parentElement.parentElement.parentElement.id == 'container' ){ 
          doThis();
      }
  }
  </code></pre>