【问题标题】:Move around dynamic divs in blog post listings在博客文章列表中移动动态 div
【发布时间】:2013-08-29 05:17:06
【问题描述】:

我正在使用博客,并希望将类别移动到每个帖子列表的标题上方。当我使用以下代码时,我得到了第一类的 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>

【问题讨论】:

  • 你能发一个 HTML 的例子吗?
  • &lt;div id="entry-2839"&gt; &lt;div class="blog-post-in"&gt; &lt;div class="blog-head"&gt;"xyzcontent"&lt;/div&gt; &lt;div class="blog-side"&gt; &lt;div class="blog-category"&gt; "morecontent"&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;

标签: javascript css each


【解决方案1】:

这应该可以解决问题:

var e = jQuery(this);
e.closest(".blog-post-in").prepend(e);

【讨论】:

  • 工作。多谢。对不起,我在评论中的 html 格式乏善可陈。
猜你喜欢
  • 1970-01-01
  • 2018-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多