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

91
Views
how to get the grid to be of the same size

i have created an input button which will add more squares to the grid but i need the grid to be of the same size regardless of how many squares i add to it while the squares become smaller to account for themselves inside the grid

const grid = 
document.querySelector('.grid');
const blackButton = 
document.querySelector('.blackbutton');
blackButton.addEventListener('click', 
blkButton);
const clear = 
document.querySelector('.clearbutton')
clear.addEventListener('click', 
clearGrid);
const eraserButton = 
document.querySelector('.eraserbutton')
eraserButton.addEventListener('click', 
ersButton)
const rainbowButton =document.querySelector('.rainbowbutton')
rainbowButton.addEventListener('click', 
rbwButton)
 //DOM handling



function getGrid(size) {
const grid = 
document.querySelector('.grid');
 const boxs = 
grid.querySelectorAll(".box");
boxs.forEach((div) => div.remove());
grid.style.gridTemplateColumns = 
`repeat( ${size} , 1fr)`;
grid.style.gridTemplateRows = `repeat( 
${size} , 1fr)`;

   let amount = size * size
    for (let i = 0; i < amount; i++) {
  const box = 
  document.createElement('div');
  box.classList.add('box');
  grid.appendChild(box);
} 
}

getGrid(16)

 function changeSize(input){
if (input >= 2 && input <= 100) {
  getGrid(input);
 }
 else {
  console.log("Only between 2 to 100 Fam!")
}

}
about 4 years ago · Santiago Gelvez
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!