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

90
Visualizações
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
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