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

151
Views
Apendchild only apending once in ForEach method
function addOrgsToCard(Data) { 
  const orgs = document.getElementById("orgs");
  const org = document.createElement("div");
  org.classList.add("org");
  Data.forEach((organisation)=>{
    org.innerHTML = `
    <div class="org">
    <img src="${organisation.avatar_url}" alt="" />
    <span>${organisation.login}</span>
    </div>
  `;
  console.log(organisation.login);
  orgs.appendChild(org);
  });
  
}

This is the function to add organization details in a div of a profile card but the problem is apendchild method is appending only one organisation detail (the last one from the API call) ,Can anyone help me solve this issue?enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

org.innerHTML = overwrites the previous value. So every time you loop over the data the previous elements get removed. You should move the creation of your org element inside the forEach loop:

function addOrgsToCard(Data) { 
  const orgs = document.getElementById("orgs");
  Data.forEach((organisation)=>{
    const org = document.createElement("div");
    org.classList.add("org");
    org.innerHTML = `
    <div class="org">
    <img src="${organisation.avatar_url}" alt="" />
    <span>${organisation.login}</span>
    </div>
    `;
    console.log(organisation.login);
    orgs.appendChild(org);
  });
}
about 4 years ago · Juan Pablo Isaza Report

0

  1. Try using only "append"(I am not sure if this works).
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!