Reputation: 582
I use this code to wrap every 3 divs in a seprate div and this works:
$('.a_paj_element:nth-child(3n)').each(function(index) {
$(this).prevAll('.a_paj_element').andSelf().wrapAll('<div class="three_paj_els" style="display:none;" />');
});
$('#paj_container > .a_paj_element').wrapAll('<div class="three_paj_els" style="display:none;" />');
I Have been trying how to assign each wrapping div its own ID in numeric order kind of like this:
<div id="1" class="three_paj_els" style="display:none;" ></div>
<div id="2" class="three_paj_els" style="display:none;" ></div>
<div id="3" class="three_paj_els" style="display:none;" ></div>
Like it Auto Increments. each ID it makes. When i try and do it I can't get it to increment.
How do I do this if it's possible? Thanks a bunch -sal
Upvotes: 2
Views: 3611
Reputation: 56467
How about this?
var ID = 0;
$('div.three_paj_els').each(function() {
ID++;
$(this).attr('id', 'id'+ID);
});
I'm not sure whether numbers alone are valid IDs.
Upvotes: 4