-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03.DOM-breakpoints.js
More file actions
38 lines (27 loc) · 901 Bytes
/
03.DOM-breakpoints.js
File metadata and controls
38 lines (27 loc) · 901 Bytes
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
function init() {
var count = 0;
function addItemToPanel() {
var panel = document.querySelector('#panel');
var item = createItem()
panel.append(item);
}
function removeItemFromPanel() {
var item = document.querySelector('#panel li');
item && item.remove();
}
function changeColor() {
var randomColor = '#' + Math.floor(Math.random() * 0xFFF).toString(16);
var panel = document.querySelector('#panel');
panel.style.color = randomColor;
}
function createItem() {
var item = document.createElement('li');
item.innerText = count;
count++;
return item;
}
document.querySelector('#click-to-expand').addEventListener('click', addItemToPanel);
document.querySelector('#click-to-remove').addEventListener('click', removeItemFromPanel);
document.querySelector('#click-to-color').addEventListener('click', changeColor);
}
init()