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

206
Views
Creating Multiple DIVS through the DOM and appending to them to the main DIV

I trying to create 121 divs through the DOM, and append to the .container div

const container= document.querySelector('.container');
const divNumber= 121;
for (let i= 0; i<= 121; i++){
  const divs= document.createElement('div');
  divs.classList.add('items');
  container.appendChild(divs);
}
.container {
  display: grid;
  grid-template-columns: auto auto auto auto auto auto auto auto auto auto auto;
}
.items {
  border: 1px solid black;
  margin: 0px;
}
<div class='container'></div>

Nothing seems to happen on the webpage. How can I make 11 by 11 which equals 121 divs through the DOM and append them to the parent div, .container in this case?

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

0

All grids are overlapping. Add grid-gap property

const container = document.querySelector('.container');
const divNumber = 121;
for (let i = 0; i < 121; i++) {
  const divs = document.createElement('div');
  divs.classList.add('items');
  divs.innerHTML = i + 1
  container.appendChild(divs);
}
.container {
  display: grid;
  grid-template-columns: repeat(11,1fr);
  grid-gap: 20px;
}

.items {
  border: 1px solid black;
  margin: 0px;
  padding: 5px;
  color: green;
}
<div class='container'></div>

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!