-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesigns.js
executable file
·38 lines (28 loc) · 1.27 KB
/
designs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const heightElement = document.getElementById('inputHeight');
const widthElement = document.getElementById('inputWidth');
const submitButton = document.getElementById('submitButton');
const table = document.getElementById('pixelCanvas');
const color = document.getElementById('colorPicker');
// event listener for submit button
var submit = submitButton.addEventListener("click", function (event) {
event.preventDefault();
table.innerHTML = '';
const heightValue = heightElement.value;
const widthValue = widthElement.value;
// loop within loop to create a table row and data elements.
for (let x = 0; x < heightValue; x++) {
const row = document.createElement("tr");
for (let y = 0; y < widthValue; y++) {
const data = document.createElement("td");
// click event listener on "data" variable to color backgrownd once clicked
var colorElement = data.addEventListener("click", function () {
color.innerHTML = '';
const colorValue = color.value;
const dataBackground = data.style.backgroundColor = colorValue;
});
// append data to row to create grid
row.appendChild(data)
}
table.appendChild(row);
}
});