-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-aula.js
59 lines (42 loc) · 1.38 KB
/
script-aula.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
55
56
57
58
59
const img = document.querySelector('img');
function callback(event) {
console.log(event);
}
// img.addEventListener('click', callback);
const animaisLista = document.querySelector('.animais-lista');
function callbackLista(event) {
console.log(event.currentTarget);
console.log(event.target);
console.log(event.type);
}
// animaisLista.addEventListener('click', callbackLista);
const linkExterno = document.querySelector('a[href^="http"]');
function handleLinkExterno(event) {
event.preventDefault();
// console.log(event);
console.log(this.getAttribute('href'));
console.log(event.currentTarget);
}
linkExterno.addEventListener('click', handleLinkExterno);
const h1 = document.querySelector('h1');
function handleEvent(event) {
console.log(event.type, event);
}
// h1.addEventListener('click', handleEvent);
// h1.addEventListener('mouseenter', handleEvent);
// h1.addEventListener('mousemove', handleEvent);
// window.addEventListener('scroll', handleEvent);
// window.addEventListener('resize', handleEvent);
function handleKeyboard(event) {
if(event.key === 'a') {
document.body.classList.toggle('azul');
}
}
window.addEventListener('keydown', handleKeyboard);
const imgs = document.querySelectorAll('img');
function handleImg(event) {
console.log(event.currentTarget.getAttribute('src'));
}
imgs.forEach((img) => {
img.addEventListener('click', handleImg);
});