Cris
Cris

Reputation: 4044

jQuery: add custom rel attribute to all links inside a div box?

I have a lot of div boxes ".box", each filled with more than 3 links. Basically I want to add a rel attribute like this.

My code so far:

$('.box a').each(function() { $(this).attr('rel','lightbox[group]'); });

Upvotes: 2

Views: 2098

Answers (1)

VisioN
VisioN

Reputation: 145408

You can try this:

$(".box").each(function(i) {
    $(this).find("a").attr("rel", "lightbox[group" + (i+1) + "]");
});

Upvotes: 5

Related Questions