Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
How can i loop html element using jquery in javascript?

I want to repeat 'post' div and all of its contents eg 50times in left-col div using jquery and call it inside html?

HTML:

 <div class="post"> Content </div>

JS:

var jQueryScript = document.createElement('script');
jQueryScript.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js');
document.head.appendChild(jQueryScript);

$(document).ready(function(i) {
for (let i = 2; i < 100; i++) {
  $(".post:eq(0)").clone().appendTo(".left-col");
}


 });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do it like this:

$(document).ready(function(i) {
  for (let i = 0; i < 50; i++) {
    $(".post:eq(0)").clone().appendTo("#left-col");
  }
});

There was a few problems with your code. First $("#post") should be $(".post"), since it's a class not an id.

Second your for loop was not correct. You were missing the {} and also it should be i < 50 not i < i.length(50)

Also important to note that I've added :eq(0) to $(".post"), since it would cause a big problem without. Because first time the loop would run, you would have 1 element with the class post, second time you would have 3 elements, third time = 6 elements and so far.

$(document).ready(function(i) {
  for (let i = 0; i < 50; i++) {
    $(".post:eq(0)").clone().appendTo("#left-col");
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="post"> Content </div>


<div id="left-col"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!