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

222
Visualizações
javascript data not appending to html webpage?

I have this simple code with 5 paramaters taken from an API that logs data:

for (i = 0; i < arr.length-1; i++) {
        
        console.log('For Calls')
        console.log(arr[i].league.name)
        console.log(arr[i].teams.home.name, arr[i].goals.home)
        console.log(arr[i].teams.away.name, arr[i].goals.away)
}

it logs this data to the console (2 sets of data shown): Logged Data

The issue I am having is trying to display this looped content to the website, I haven't even been able to get it on the screen so far using the .append methods.

Here is the format I am trying to create:

<div class="parentDiv">
    <div class="league">Data goes here</div>
    <div class="team1">Data goes here</div>
    <div class="score1">Data goes here</div>
    <div class="team2">Data goes here</div>
    <div class="score2">Data goes here</div>
</div>

I am aware I can give each div a class and append that way but I need this in a loop so those methods do not work for me in this circumstance.

Any Tips are Appreciated.

My current attempt:

for (i = 0; i < filtered.length-1; i++) {


    let parent = document.createElement("div")
    parent.className = 'parentDiv'
  
    let homeTeamName = document.createElement("div")
    homeTeamName.className = 'league'
    homeTeamName.innerHTML = filtered[i].league.name
    parent.appendChild(homeTeamName)
  
    let homeTeamScore = document.createElement("div")
    homeTeamScore.className = 'team1'
    homeTeamScore.innerHTML = filtered[i].teams.home.name
    parent.appendChild(homeTeamScore)

    let awayTeamName = document.createElement("div")
    awayTeamName.className = 'score1'
    awayTeamName.innerHTML = filtered[i].teams.home.name
    parent.appendChild(awayTeamName)

    let awayTeamScore = document.createElement("div")
    awayTeamScore.className = 'team2'
    awayTeamScore.innerHTML = filtered[i].teams.home.name
    parent.appendChild(awayTeamScore)

  
  }

It prints nothing to the dom, blank page. You can use the web console at footballify.net/test

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You never Attach the "parent" variable to your body

Try:

document.body.append(parent) at the end
about 4 years ago · Juan Pablo Isaza Relatório
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