views:

37

answers:

1

I'm using colorbox, i just get undefined as my get values?

$('.banner').colorbox({
    opacity: 0.4,
    href: 'dialogs/ban_add_edit.php?banner_to_edit='+$(this).attr('id')+'&typeofbanner='+$(this).attr('rel')            
    })
+2  A: 

You can do this:

$('.banner').each(function() {
  $(this).colorbox({
    opacity: 0.4,
    href: 'dialogs/ban_add_edit.php?banner_to_edit='+this.id+'&typeofbanner='+$(this).attr('rel')            
  });
});

In your current code this refers to whatever you're running this in, probably a document.ready function (so this = document). In this version, you're looping through .banner elements, and this refers to the element you're on as you loop.

One more change is this.id, I often do this to, but no need for $(this).attr('id') unless you need to handle it being chained later...this.id raw DOM style is shorter and faster :)

Nick Craver
worked a treat, thanks for the tip on using the this object tooH
Haroldo
please accept the answer if it worked for you.
lugte098
What's wrong with `this.rel`?
J-P
@J-P: I don't think IE likes it.
fudgey