我正在处理一个博客,希望在每个帖子列表的标题上方移动类别。当我使用以下代码时,我得到了50个第一类的克隆。我想我需要使用.each()
的索引参数,但我不确定。这是我的代码:
jQuery(document).ready(function(){
jQuery(".blog-category").each(function(){
jQuery(this).insertBefore( jQuery(".blog-head") ) ;
});
});
本质上,我正在尝试插入
.blog-category
之前
.blog-head
在每个帖子上。
HTML
<div id="entry-2839">
<div class="blog-post-in">
<div class="blog-head">content</div>
<div class="blog-side">
<div class="blog-category">more content</div>
</div>
</div>
</div>
这应该可以做到:
var e = jQuery(this);
e.closest(".blog-post-in").prepend(e);