title: jQuery get multiple id attribute on click
body: <p>I'm trying to get the id attr from different onclicks.</p>
  
  <p>Here is the html I have. </p>
  
  <pre><code>&lt;div id="name-1"&gt; 
      &lt;a href="#" class="view"&gt;
  &lt;div&gt; 
  
  &lt;div id="name-2"&gt; 
      &lt;a href="#" class="view"&gt;
  &lt;div&gt; 
  
  &lt;p&gt;Name: &lt;span class='name'&gt;&lt;/span&gt;&lt;/p&gt;
  
  &lt;script&gt;
  $(".view").click(function() {
      var id = $(".view").closest("div").attr("id");
      $('.name').html(id);    
  }); 
  &lt;/script&gt;
  </code></pre>
  
  <p>When I click the first view I see "name-1" however when I click the second view nothing happens. Also, when I click the second name it shows "name-1". I know this is probably easy to solve but it's friday so I appreciate the help. </p>