Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda