Search code examples
jqueryhtmlimagecopyclone

Copy url and paste it in src


I'm trying to modify a gallery, so I wouldn't have to paste the link several times.

Can anyone advice the best method to copy the link from a href to the image src??

Here is my markup:

<li>
<a class="thumb resize2" id="img2" name="drop" href="http://farm3.static.flickr.com/2404/2538171134_2f77bc00d9.jpg" title="Title #1">
   <img class="resize1" id="img2-2" src="" alt="Title #1" />
</a>
<div class="caption">
   Any html can be placed here ...
</div>
</li>

and is it posible to make a variable from the li #img2 and img2-2

For example: I have 10 images places in li and the link to the image is placed only onces, so the script will run through all li's and copy and paste the links in particular li? Did I make myself clear what I want to achieve?

I'm trying to achieve this using jQuery.

Thanks guys,


Solution

  • $('li a.thumb').each(function(){
      var href = $(this).attr('href');
      $(this).find('img').attr('src',href);
    });