我在页脚使用此:保持insertAfter元素,在它自己的父元素
它应该重新安排与项目的一些元素,如:日发表,作者,标签,评论数量低于文章内容,而不是上面。
问题是,在他们多于一篇文章的页面上(例如:Blog Roll),它会将所有数据(作者/标签等)插入到每篇文章中,而不是每篇文章中,乘以数据。
例如,假设有两篇文章。期望的结果是将第一篇文章内的第一篇文章中的发布日期,作者,标记和评论数移至第二篇文章的相同内容。 jQuery脚本正在这样做,但它也将第一篇文章数据添加到第二篇文章中,反之亦然。
我该如何使它只在它自己的文章中预先插入/插入?
这是问题的一个小提琴:https://jsfiddle.net/gb14ugja/
香草HTML:
<article id="post-239" class="hentry">
<span class="posted-on" style="color:blue">Date Published: 1/25/2017,</span>
<div class="some-title">
Blue Article
</div>
<div class="entry-meta" style="color:blue">
<span>Article One Author,</span>
<span>Article One Tags,</span>
<span>Article One Comment Count.</span>
</div>
<p class="entry-content">This is the Blue Article, the red articles content should not be here!</p>
</article>
<hr/>
<article id="post-84" class="hentry">
<span class="posted-on" style="color:red">Date Published: 1/28/2017,</span>
<div class="some-title">
Red Article
</div>
<div class="entry-meta" style="color:red">
<span>Article Two Author,</span>
<span>Article Two Tags,</span>
<span>Article Two Comment Count.</span>
</div>
<p class="entry-content">This is the Red Article, the blue articles content should not be here!</p>
</article>
不希望HTML结果:
<article id="post-239" class="hentry">
<div class="some-title">
Blue Article
</div>
<p class="entry-content">This is the Blue Article, the red articles content should not be here!</p>
<div class="entry-meta" style="color:blue"><span class="posted-on" style="color:blue">Date Published: 1/25/2017,</span><span class="posted-on" style="color:red">Date Published: 1/28/2017,</span>
<span>Article One Author,</span>
<span>Article One Tags,</span>
<span>Article One Comment Count.</span>
</div>
<div class="entry-meta" style="color:red"><span class="posted-on" style="color:blue">Date Published: 1/25/2017,</span><span class="posted-on" style="color:red">Date Published: 1/28/2017,</span>
<span>Article Two Author,</span>
<span>Article Two Tags,</span>
<span>Article Two Comment Count.</span>
</div>
</article>
<hr>
<article id="post-84" class="hentry">
<div class="some-title">
Red Article
</div>
<p class="entry-content">This is the Red Article, the blue articles content should not be here!</p>
<div class="entry-meta" style="color:blue"><span class="posted-on" style="color:blue">Date Published: 1/25/2017,</span><span class="posted-on" style="color:red">Date Published: 1/28/2017,</span>
<span>Article One Author,</span>
<span>Article One Tags,</span>
<span>Article One Comment Count.</span>
</div>
<div class="entry-meta" style="color:red"><span class="posted-on" style="color:blue">Date Published: 1/25/2017,</span><span class="posted-on" style="color:red">Date Published: 1/28/2017,</span>
<span>Article Two Author,</span>
<span>Article Two Tags,</span>
<span>Article Two Comment Count.</span>
</div>
</article>
所需的HTML结果:
<article id="post-239" class="hentry">
<div class="some-title">
Blue Article
</div>
<p class="entry-content">This is the Blue Article, the red articles content should not be here!</p>
<span class="posted-on" style="color:blue">Date Published: 1/25/2017,</span>
<div class="entry-meta" style="color:blue">
<span>Article One Author,</span>
<span>Article One Tags,</span>
<span>Article One Comment Count.</span>
</div>
</article>
<hr/>
<article id="post-84" class="hentry">
<div class="some-title">
Red Article
</div>
<p class="entry-content">This is the Red Article, the blue articles content should not be here!</p>
<span class="posted-on" style="color:red">Date Published: 1/28/2017,</span>
<div class="entry-meta" style="color:red">
<span>Article Two Author,</span>
<span>Article Two Tags,</span>
<span>Article Two Comment Count.</span>
</div>
</article>
编辑:我用更多的数据修改了这个问题,因为有些人很难理解我遇到的问题。我所包括的小提琴也进行了大修,跳起来会更明显,因为问题在于。
此外,每篇文章都分配了一个带有随机数的ID。我试图移动每个文章ID(article[id^='post-*']
)的数据,但没有占上风。
你试图使用.find或.closest方法? –
提供适当的代码上下文,你使用这个 – charlietfl
我添加了一个演示问题的小提琴。 – Xarcell