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

210
Vistas
How to create and append new divs inside a loop?

I am working on a twitter like app for class. I am trying to create a new $tweet for each loop iteration and append each &tweet into my $feed container. However, when run, only the first tweet in the array is shown. My hypothesis is that only one $tweet is being created and appended and that each iteration simply overwrites it. Heres my sample code.

var renderfeed = function() {
  $feed.empty();
  var index = streams.home.length - 1;
  while (index >= 0) {
    // for (var i = 0; i < index + 1; i++) {
    var tweet = streams.home[index];
    var $tweet = $('<div class="tweet"></div>');
    $tweet.appendTo($feed);
    console.log(tweet);
    console.log(streams.home);
    console.log($tweet);


    //assingning values to variable to be pushed into $tweet div, icons already established
    $userName.text('@' + tweet.user);
    $profilePhoto.attr("src", tweet.profilePhotoURL);
    $message.text(tweet.message);
    $timeStamp.text(tweet.created_at);

    //appending child elements to $tweet
    $profilePhoto.appendTo($tweet);
    $userName.appendTo($tweet);
    $message.appendTo($tweet);
    $timeStamp.appendTo($tweet);
    $like.appendTo($tweet);
    $retweet.appendTo($tweet);
    $comment.appendTo($tweet);
    $share.appendTo($tweet);

    index -= 1;
  }
};
  • Streams.home is an array of objects
about 4 years ago · Juan Pablo Isaza
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