我正在使用博客,并希望在每个帖子列表上移动标题上方的类别。当我使用以下代码时,我获得了第一类的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>
答案 0 :(得分:3)
这应该可以解决问题:
var e = jQuery(this);
e.closest(".blog-post-in").prepend(e);