title: HTML/Jquery: $('a').attr('href') and .each?
body: <p>My questions regards HTML and Jquery.</p>
  
  <p>I have some links in HTML code, something like this:</p>
  
  <pre><code>&lt;a href="#box1"&gt;Item1&lt;/a&gt;
  &lt;a href="#box2"&gt;Item2&lt;/a&gt;
  &lt;a href="#box3"&gt;Item3&lt;/a&gt;
  etc.
  </code></pre>
  
  <p>In my current JQuery script, I have the following code:</p>
  
  <pre><code>$(function () {
      var targetbox = $('a').attr('href');
      $('a').click(function (event) {
          $(targetbox).fadeIn(2000);
          $('#showtext').text(targetbox);
      });
  });
  </code></pre>
  
  <p>What this script does (or should do eventually) is fade in one of the hidden divs (#box1, #box2, etc) depending on what link (see HTML code) is clicked. I added the #showtext div to see of the attribute is being correctly stored.</p>
  
  <p>The script works fine, however, only with the first href attribute that is found in the first link. I am aware that $('a').attr('href') grabs only the attribute of the first 'a' element and that I need to add .each somewhere, but I am lost as to where exactly to add this. I tried adding in several places but it stopped the code working.</p>
  
  <p>Thank you for help.</p>
  
  <p>Gee</p>