-
Notifications
You must be signed in to change notification settings - Fork 0
/
04.event-breakpoints.js
56 lines (40 loc) · 1.47 KB
/
04.event-breakpoints.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
47
48
49
50
51
52
53
54
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);
$('#click-to-expand2').click(addItemToPanel);
$('#click-to-remove2').click(removeItemFromPanel);
$('#click-to-color2').click(changeColor);
function logEvent(event) {
console.log(event.type)
}
document.querySelector('#panel').addEventListener('mouseover', logEvent)
document.querySelector('#panel').addEventListener('mouseenter', logEvent)
document.querySelector('#panel').addEventListener('mouseleave', logEvent)
document.querySelector('#panel').addEventListener('mouseout', logEvent)
window.addEventListener('click', function() {
console.log('Window is clicked!')
})
}
init()