diff --git a/main.js b/main.js index 79a0fd1..bc00c00 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,29 @@ // Please feel free to change the JS as you see fit! This is just a starting point. +const colorDropdown = document.getElementById("color-select"); +const fillButton = document.getElementById("fill-grid"); + +let selectedColor = colorDropdown.value; + +colorDropdown.addEventListener("change", () => { + selectedColor = colorDropdown.value; +}) + + + const root = document.getElementById("root"); root.addEventListener("click", (event) => { - console.log(event.target.tagName); - console.log(event.target); + // console.log(event.target.tagName); + // console.log(event.target); + if (event.target.tagName === "TD") { + event.target.style.backgroundColor = selectedColor; + } }); + + +fillButton.addEventListener('click', () => { + const cells = document.getElementsByTagName("td"); + for (let i = 0; i < cells.length; i++) { + cells[i].style.backgroundColor = selectedColor; + } +})