Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        4年前关闭。
                    
                
        

我在此链接上有输出代码的智能模板:

My other Question in Stackoverflow

我的问题是那里没有提供的代码:每5个元素重复插入的HTML ...

有人可以通过提供解决方案来帮助我使我能够在每5个元素之后插入其他潜水内容,以使最终输出看起来像这样:

    <section id="listings" class="list clearfix">
<article class="item">
<article class="item">
<article class="item">
<article class="item">
<article class="item">

**OTHER DIV BY CLASS OR ID**

<article class="item">
<article class="item">
<article class="item">
<article class="item">
<article class="item">


**OTHER DIV BY CLASS OR ID**

<article class="item">
<article class="item">
<article class="item">
<article class="item">
<article class="item">


**OTHER DIV BY CLASS OR ID**

<article class="item">
<article class="item">
<article class="item">
<article class="item">
<article class="item">
</section>

最佳答案

使用nth-child选择器和after()

$('.item:nth-child(5n)').after('<article>inserted after 5th</article>');




$('.item:nth-child(5n)').after('<article>inserted after 5th</article>');

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<section id="listings" class="list clearfix">
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>



  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>




  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>



  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
  <article class="item">test</article>
</section>

09-26 19:18