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

240
Views
How to create a div with a specified innerHTML and store it into a variable for future use?

I created two createCardNote function First one pull data information from the state.countries Second is from state.borders

in the createCountryCardNode, console.log(cardDiv) has value thus can be seen in the console

However, createBorderCardNode, console.log(borderDiv) has no value at all

Both codes are the same why has different outcomes?

function createCountryCardNode(country) {
const cardDiv = document.createElement('div');
cardDiv.className = 'country';

cardDiv.innerHTML = `
<img class="country__img" src="${country.flag}" />
<div class="country__data">
  <h3 class="country__name">${country.name}</h3>
  <h4 class="country__region">${country.region}</h4>
  <p class="country__row"><span>๐Ÿ‘ซ</span>${country.population}</p>
  <p class="country__row"><span>๐Ÿ—ฃ๏ธ</span>${country.languages[0].name}</p>
  <p class="country__row"><span>๐Ÿ’ฐ</span>${country.currencies[0].name}</p>
</div>`;

console.log(cardDiv);
return cardDiv;
}

function createBorderCardNode(border) {
const borderDiv = document.createElement('div');
borderDiv.className = 'country';

// console.log(border.flags.svg);
// console.log(border.name.common);
// console.log(border.region);
// console.log(border.population);
// console.log(border.languages[0].name);

borderDiv.innerHTML = `
<img class="country__img" src="${border.flags.svg}" />
<div class="country__data">
  <h3 class="country__name">${border.name.common}</h3>
  <h4 class="country__region">${border.region}</h4>
  <p class="country__row"><span>๐Ÿ‘ซ</span>${border.population}</p>
  <p class="country__row"><span>๐Ÿ—ฃ๏ธ</span>${border.languages[0].name}</p>
  
</div>
`;

console.log(borderDiv);
return borderDiv;
}
about 4 years ago ยท Santiago Trujillo
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!