Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:44:16+00:00 2026-06-10T08:44:16+00:00

I need to run this function every X number of posts and the page

  • 0

I need to run this function every X number of posts and the page uses AJAX to load in new posts as you scroll down the page. I was hoping to use the function below using a for loop with the modulus operator but it doesn’t seem to accomplish what i’m looking for. Any idea how to do this?

$(document).ready(function($) {
function adTileLoop(){
        var adTile = "<div class='new-box' id='article-tile'></div>";
        var adLoc = 11;
        var p = $('#article-tile');
        var tile = $('#article-tile:nth-child('+adLoc+')');
        for(var i = 0; i <= p.length; i++){
                        if(i % adLoc == 0){
                            $(tile).after(adTile);
                        }
        }
}
$('#content').live(adTileLoop);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:44:18+00:00Added an answer on June 10, 2026 at 8:44 am

    First of all, you need to be careful to keep IDs unique. The fact that you have $("#article-tile") and you are trying to select more than one is a mistake. ID’s must be unique.

    Here’s a better way to run over a bunch of divs with jQuery:

    $("div").each(function() {
        console.log($(this));
    });
    

    You can then improve the selector to select only nth-children as you do in your question:

    $("div:nth-child(2)") for example will get every other div on the page.

    To retrieve the information about your posts specifically, use a selector specific to each post, something like: $(".post:nth-child(2)").

    As Ashirvad suggested in the comments, you can run this after a successful ajax call and you will be able to retrieve the updated information about your page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically my issue comes down to this, I need to run code on a
I'm looking to repeat this function every five seconds: function check_votes(id) { $.ajax({ type:
I need to run a certain function in every ActionResult and return a certain
I need to run this line from my c++ program: java -jar test.jar text1
I need to run a loop in SQL. Google this is a little hard
I have a statement similar to this that I need to run in Linq.
For reasons that are irrelevant to this question I'll need to run several SQLite
This seems like it should be something I already know. We need to run
I need to run a few code on every request, always depending on If
In my app I need to run a 5 digits number through an algorithm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.