title: Getting parent element in jQuery
body: <p>I have tried to get the parent element's id of the clicked element. I have tried this</p>
  
  <pre><code>$(window).click(function(event) {
      alert("Clicked on " + event.target.id + ". Its parent is " + $(event.target).parent().attr("id"));
  });
  </code></pre>
  
  <p>If I have the following structure, it returns <code>Clicked on x. Its parent is undefined</code>.</p>
  
  <pre><code>&lt;div id="y"&gt;
      &lt;div id="x"&gt;X&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Why isn't it giving the parent's id? </p>
  
  <p>I have tried the following too</p>
  
  <pre><code>$(this).closest("div").attr("id");
  $(this).parent().attr('id')
  </code></pre>