Milksamsa
Milksamsa

Reputation: 319

Change multiple attributes with Jquery

I'm building an image gallery and have been able to get the clicked thumbnail image to be loaded in the main #large div a new src for the tag. I'm trying to get the rel attribute also, in order to populate the rel attribute in the tag.

Here's my code...

$(document).ready(function() {
    $('a.thumbnail').live("click", function() {
        $('#large').hide();
        $('#project-image').css('background-image', "url('/assets/images/ajax-loader.gif') no-repeat");

     //   var i = $('<img />').attr('src',this.href).load(function() {

        var i = $('<img />').attr({    
        src: this.href,
        rel: MISSING REL SELECTOR

        }).load(function() {




            $('#large').attr('src', i.attr('src'));
            $('#large').attr('rel', i.attr('rel'));
          $('#project-image').css('background-image', 'none');
            $('#large').fadeIn();
    });

        return false; 
    });
});

What's the proper selector to load the rel attribute in the i array?

Upvotes: 0

Views: 386

Answers (3)

Jaibuu
Jaibuu

Reputation: 578

Maybe you need a

$(this).children('img').attr('rel')

in place of your MISSING REL SELECTOR

Upvotes: 0

Zut
Zut

Reputation: 639

I think you want to use $(this).attr('rel'), and not simply this.attr('rel').

Upvotes: 2

Alex Peattie
Alex Peattie

Reputation: 27637

I think you want:

rel: this.attr('rel')

Upvotes: 2

Related Questions