Reputation: 4044
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.
".box"
add rel="lightbox[group1]"
to each link inside it".box"
add rel="lightbox[group2]"
to each link inside it".box"
add rel="lightbox[group3]"
to each link inside itMy code so far:
$('.box a').each(function() { $(this).attr('rel','lightbox[group]'); });
Upvotes: 2
Views: 2098
Reputation: 145408
You can try this:
$(".box").each(function(i) {
$(this).find("a").attr("rel", "lightbox[group" + (i+1) + "]");
});
Upvotes: 5