Add href to all img jQuery

This simple function will add a href to all images on your page and link them to the img src

$('img').each(function ()
{
    var currImg = $(this);  // cache the selector
    currImg.wrap("<a href='" + currImg.attr("src") + "'></a>");
});

It is also possible to only append href to images with a certain class or in a specific div

    $(".myDiv").find('img').each(function () {
        var currImg = $(this); // cache the selector
        currImg.wrap("<a href='" + currImg.attr("src") + "'></a>");
    });

I have used this option to load images with Lightbox2, using the following code

    $(".myDiv").find('img').each(function () {
        var currImg = $(this); // cache the selector
        currImg.wrap("<a href='" + currImg.attr("src") + "'" + "rel='lightbox'" + "title='Caption...'" + "></a>");
    });