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

  • Home
  • SEARCH
  • 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 8772065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:56:55+00:00 2026-06-13T17:56:55+00:00

I am trying to get a <div class=clear></div> to appear after every third iteration

  • 0

I am trying to get a <div class="clear"></div> to appear after every third iteration of a for loop in jquery. I know in PHP it can be accomplished via if($i%3 == 0) but how does one do it in jquery/javascript?

Here is my for loop:

var data = $.parseJSON(result);
for(i=0;i<data.length;i++){
    if(i/3 == 1){
        $('#add_product_preview_area').append('<div class="clear"></div>');
    }
    $('#add_product_preview_area').append(data[i]);
}

Now this only works once since the loop will only get to the number 3 once. So any thoughts on how to make the same php concept work in jquery? I have seen the other questions about wrapping every nth in a div, but I just need to write the html of a div after each one.

Thanks in advance.

EDIT:

if ( i && (i % 3 === 0)) {

Is the answer..I didn’t know you could do that. Thanks!

  • 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-13T17:56:57+00:00Added an answer on June 13, 2026 at 5:56 pm

    Use the modulus operator instead.

    if ( i && (i % 3 === 0)) { ...
    

    Whenever there’s no remainder, you’re evenly divisible by 3.

    I included the i && to eliminate the first iteration since 0 % 3 === 0; // true.

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

Sidebar

Related Questions

I'm trying to get a div to fade in using jquery, when the mouse
I am trying to get the contents from span, class, div from external other
I'm trying to get 2 divs on the same line, I've got <div class=header>
So i am trying get 2 div-containers which both should contain centered text (Both
HI I am trying to get div from getelementbyid but it isnt working for
IM trying to get the div content not to flow past the footer, I
Im trying to get infinite scroll inside of a div to work based off
Im trying to get a Gutter Width of 10px between my Div's, but it
I'm trying to get the width of a div container to set another css
I'm trying to get the first paragraph height within a div and store it

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.