gpt4 book ai didi

jquery - 如何用div替换每5篇文章?

转载 作者:行者123 更新时间:2023-12-01 07:52:22 25 4
gpt4 key购买 nike

我正在研究这个 tumblr 主题 ( http://trollfutbol.tumblr.com/ ),因为 tumblr 会在文章中自动生成帖子,为了在其中一些文章之间添加广告,我只想将每 5 篇文章替换为我将在其中添加的 div 300x250 广告。

我正在谈论的部分的 Html:

<div class="content">
<article></article>
<article></article>
<article></article>
<article></article>
<article></article> Automically generating as many posts as I have.
<article></article>
<article></article>
<article></article>
<article></article>
</div>
<div class="ad">
</div>

我尝试这样做:

<script>    
$('article:nth-child(5n)').replaceWith('.ad');
</script>

最佳答案

您需要克隆元素以附加到多个元素:

$('article:nth-child(5n)').replaceWith($('.ad').clone());

<强>

Working Demo

关于jquery - 如何用div替换每5篇文章?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28242278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com