Hi everyone!
I tried to make a dynamic grid of 12 cases (4 columns and 3 rows).
I need to generate 12 divs. Each one is a grid child and has a “hit” class and a data-id between 0 and 11.
But my console displays : Uncaught TypeError: document.querySelector(…).createElement is not a function at line 11.
let newCase = document.querySelector('.grid').createElement('div');
from :
let caseTaille = 84;
let gridRows = 3;
let gridColumns = 4;
let gridWidth = caseTaille * gridColumns;
let gridHeight = caseTaille * gridRows;
let total = gridRows * gridColumns;
for (i = 0; i < total; i++) {
// Create child boxes in grid div
let newCase = document.querySelector('.grid').createElement('div');
newCase.classList.add('hit');
newCase.id.add('data-id');
let dataId = newCase.getAttribute('data-id');
// Increment data-id
dataId ++;
// Positioning of the boxes in the grid
newCase.style.top = dataId / gridWidth;
newCase.style.left = dataId % gridWidth;
console.log(newCase.style.top);
};
Index.html :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Exercice modulo</title>
</head>
<body>
<div class="grid"></div>
<script src="index.js"></script>
</body>
</html>
Does anyone know why? I checked the MDN documentation and I think I used the methods correctly.
Thank you and have a nice day!