Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda