Find Closest link with jQuery
<p>I have a list of items that looks similar to this:</p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;
    &lt;h3 class="headings"&gt; &lt;a href="page1.html"&gt;&lt;/a&gt; &lt;/h3&gt;
    &lt;div class="details"&gt;
      &lt;p&gt;Item Details&lt;/p&gt;
      &lt;a href="#" class="linktoitem"&gt;Click Here&lt;/a&gt; &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;h3 class="headings"&gt; &lt;a href="page2.html"&gt;&lt;/a&gt; &lt;/h3&gt;
    &lt;div class="details"&gt;
      &lt;p&gt;Item Details&lt;/p&gt;
      &lt;a href="#" class="linktoitem"&gt;Click Here&lt;/a&gt; &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;h3 class="headings"&gt; &lt;a href="page3.html"&gt;&lt;/a&gt; &lt;/h3&gt;
    &lt;div class="details"&gt;
      &lt;p&gt;Item Details&lt;/p&gt;
      &lt;a href="#" class="linktoitem"&gt;Click Here&lt;/a&gt; &lt;/div&gt;
  &lt;/li&gt;
</code></pre>

<p></p>

<p>My aim is to add to Click Here linkk from inside h3 inside the same li. HEre is how Im trying to do it:</p>

<pre><code>$('li').each(function(){
    var linkitem = $('.linktoitem').closest('h3').find('a').attr('href');
    $('a.linktoitem').attr('href' , linkitem) 
});
</code></pre>

<p>Unfortunately link comes out as undefined.</p>

<p>Any help much appreciated.</p>
