-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
48 lines (34 loc) · 1.41 KB
/
main.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
39
40
41
42
43
44
45
46
document.addEventListener('DOMContentLoaded',()=>{
const container = document.querySelector('.container');
for(let i=0;i<16;i++){
for (let j=0;j<16;j++){
const square = document.createElement('div');
square.setAttribute('class','square');
container.appendChild(square);
square.addEventListener('mouseenter',()=>{
square.style.backgroundColor='blue';
})
}
}
const button = document.querySelector('button');
button.addEventListener('click',()=>{
const value=prompt("Add the number of grids");
const parent = document.querySelector('.container');
const child = Array.from(parent.children);
child.forEach(element => {
parent.removeChild(element);
});
const containerwidth=parseInt(value)*40;
container.setAttribute('style',`width:${containerwidth}px; height:auto`)
for (let k=0;k<value;k++){
for(let l=0;l<value;l++){
const square = document.createElement('div');
square.setAttribute('class','square');
container.appendChild(square);
square.addEventListener('mouseenter',()=>{
square.style.backgroundColor='blue';
})
}
}
})
})