title: jQquery : add specific attr to each image
body: <p>There is a loop (in my gallery script) that result me something like this :</p>
  
  <pre><code>        &lt;div class="gallery"&gt;
              &lt;a href="uploads/rep2.png"&gt;
               &lt;img src="uploads/rep2-150x110.png" class="thumbnail"&gt;
              &lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="gallery"&gt;
              &lt;a href="uploads/rep1.png"&gt;
               &lt;img src="uploads/rep1-150x110.png" class="thumbnail"&gt;
              &lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="gallery"&gt;
              &lt;a href="uploads/rep2.png"&gt;
               &lt;img src="uploads/rep2-150x110.png" class="thumbnail"&gt;
              &lt;/a&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>I want add specific attr (that is "href" of each link) to each image in this loop. Must be:</p>
  
  <pre><code>        &lt;div class="gallery"&gt;
              &lt;a href="uploads/rep2.png"&gt;
               &lt;img data-img="uploads/rep2.png" src="uploads/rep2-150x110.png" class="thumbnail"&gt;
              &lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="gallery"&gt;
              &lt;a href="uploads/rep1.png"&gt;
               &lt;img data-img="uploads/rep1.png" src="uploads/rep1-150x110.png" class="thumbnail"&gt;
              &lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="gallery"&gt;
              &lt;a href="uploads/rep2.png"&gt;
               &lt;img data-img="uploads/rep2.png" src="uploads/rep2-150x110.png" class="thumbnail"&gt;
              &lt;/a&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>I wrote this code:</p>
  
  <pre><code>$('.thumbnail').each(function() {
  var $this = $('.gallery a'),
  href = $this.data('href'); 
  $('.thumbnail').attr('data-img', href);
          });
  </code></pre>
  
  <p>But not work.Thanks for any help.</p>