我有一个由8个div组成的列表,并需要使用Jquery为它们添加一系列类号,以便分别对它们进行样式设置。需要将它们添加到“content-block” div中,如下所示:
期望的效果将类似于这样:
<div class="wrapper">
<div id="content-block" *class="post1"*>
</div></div>
<div class="wrapper">
<div id="content-block" *class="post2"*>
</div></div>
我已经添加了这个脚本。
**Javascript**
$('.post-block').each(function(i){
$(this).addClass('post' + i);})
但我需要使用锚链接将它们链接起来,因此需要一种添加ID到帖子块的方法。
Desired effect
**HTML**
<div id="post1" class="post-block">
</div>
<div id="post2" class="post-block">
</div>
非常感谢