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

199
Views
¿Cómo puedo hacer un bucle del elemento html usando jquery en javascript?

¿Quiero repetir el div 'post' y todo su contenido, por ejemplo, 50 veces en el div de la columna izquierda usando jquery y llamarlo dentro de 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

Puedes hacerlo así:

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

Hubo algunos problemas con su código. Primero $("#post") debe ser $(".post") , ya que es una clase, no una identificación.

En segundo lugar, su bucle for no era correcto. Te faltaba el {} y también debería ser i < 50 no i < i.length(50)

También es importante tener en cuenta que agregué :eq(0) a $(".post") , ya que causaría un gran problema sin él. Porque la primera vez que se ejecutaría el bucle, tendría 1 elemento con la post de clase, la segunda vez tendría 3 elementos, la tercera vez = 6 elementos y hasta ahora.

 $(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!