-
Notifications
You must be signed in to change notification settings - Fork 928
Expand file tree
/
Copy pathdesigns.js
More file actions
40 lines (35 loc) · 1.17 KB
/
designs.js
File metadata and controls
40 lines (35 loc) · 1.17 KB
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
39
40
// Select color input
const tableColor = document.getElementById('inputColor');
// Select size input
const tableHeight = document.getElementById('inputHeight');
const tableWidth = document.getElementById('inputWidth');
// When size is submitted by the user, call makeGrid()
function makeGrid() {
var myTable = document.getElementById('pixelCanvas');
for (let i = 0; i < tableHeight.value; i++) {
const row = myTable.insertRow(0);
for (let j = 0; j < tableWidth.value; j++) {
const cell = row.insertCell(0);
cell.innerHTML = "";
cell.style.border = '1px solid gray';
cell.style.width = '40px';
cell.style.height = '40px';
}
}
}
// Your code goes here!
const form = document.getElementById('sizePicker');
form.addEventListener('submit', function(event) {
event.preventDefault();
makeGrid();
console.log("Making Grid, baby!");
});
function addColor(event) {
if (event.target.tagName === 'TD') {
var color = document.getElementById('colorPicker').value;
event.target.style.backgroundColor = color;
event.preventDefault();
}
}
const colorThis = document.getElementById('pixelCanvas');
colorThis.addEventListener('click', addColor);