JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div id="board"></div>
</body>
CSS
.tile {
display: inline-block;
height: 25vh;
width: 30%;
margin: 0 3px;
border: 1px solid black;
}
JavaScript
// click-event
function changeColor(specificElement) {
'use strict';
specificElement.style.backgroundColor = 'yellow';
}
// create game
var gameContainer = document.getElementById('board');
var createBoard = function() {
'use strict';
var index, square;
for (index = 0; index < 6; index += 1) {
square = document.createElement('div');
square.className = 'tile';
// tile event
square.addEventListener('click', changeColor(this));
gameContainer.appendChild(square);
}
};
createBoard();