title: Jquery set attribute to every element
body: <p>I want to set attribute of every a tag as img tag's src.</p>
  
  <p>Here is what I did.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
  
   var href=$('.single img').attr('src');
   $('.single').attr('href',href);
   $(".single").fancybox({
            helpers: {
                title : {
                    type : 'float'
                }
            }
        });
        
  })</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet"/&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.js"&gt;&lt;/script&gt;
  &lt;a class="single" &gt;
   &lt;img src="http://farm2.staticflickr.com/1661/24170619595_ca34ef74d9_m.jpg" alt="" /&gt;
  &lt;/a&gt;
  &lt;a class="single" &gt;
   &lt;img src="http://farm2.staticflickr.com/1514/23919332220_60b7867d60_m.jpg" alt="" /&gt;
  &lt;/a&gt;
  &lt;a class="single" &gt;
   &lt;img src="http://farm2.staticflickr.com/1669/23976340262_a5ca3859f6_m.jpg" alt="" /&gt;
  &lt;/a&gt;
  &lt;a class="single" &gt;
   &lt;img src="http://farm2.staticflickr.com/1459/23610702803_83655c7c56_m.jpg" alt="" /&gt;
  &lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>But every a tag has same href. </p>
  
  <p>How can I fix this</p>