-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (38 loc) · 1.18 KB
/
Copy pathscript.js
File metadata and controls
50 lines (38 loc) · 1.18 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
41
42
43
44
45
46
47
48
49
50
function changeColor(e) {
let rdmColor = "#" + Math.random().toString(16).substr(2, 6)
// console.log(rdmColor)
e.target.style.background = rdmColor
}
function whiteOn() {
event.target.style.background = "#fff"
}
function createSquareBlocks(squareSide) {
templateBlock = `
<td class="squareTable"></td>
`
table = document.createElement("table")
document.querySelector("main").appendChild(table)
createTableRow(squareSide)
document.querySelectorAll("td").forEach(item => {
item.addEventListener("mouseover", changeColor)
item.addEventListener("mouseout", whiteOn)
item.addEventListener("click", event => {
item.replaceWith(item.cloneNode(true));
})
})
}
function createTableRow(squareSide) {
for(i=0;i<squareSide;i++) {
tableRow = document.createElement("tr")
document.querySelector("table").appendChild(createTableData(squareSide))
}
}
function createTableData(squareSide) {
for(y=0;y<squareSide;y++) {
td = document.createElement("td")
td.classList.add("squareTable")
tableRow.appendChild(td)
}
return tableRow
}
createSquareBlocks(5)