tags:

views:

93

answers:

2

Hi,

Im trying to make my img link to this same image. Unfortunately it is not working.

<img src="someimage.jpg" width="120" height="120" />

and this is what im trying to acheave:

<a href="someimage.jpg">
    <img src="images/6208606.jpg" width="120" height="120" />
</a>

but this don't seems to be working

var ImgScr = $('.gallery img').attr('scr');

$('.gallery img').wrap('<a></a>').attr('href', ImgScr);

Any help very appreciate

+6  A: 

Shouldn't that be attr('src') and not attr('scr')?

RegDwight
+2  A: 

The wrap function doesn't return the newly created element so you are applying the href attribute to the img tag instead of the anchor tag. You may try this instead:

$('.gallery img').wrap($('<a></a>').attr('href', ImgScr));
Darin Dimitrov
That is what im after, thank you very much
Dom
You are wrong, wrap methods returns the wrapped set.
Braveyard
So what method should it be? Result returns what im after to be honest
Dom
@Aaron, are you sure? console.log($('img').wrap('<a></a>')); prints "img" in my FireBug console.
Darin Dimitrov