我在頁腳使用此:保持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