-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex002.html
54 lines (42 loc) · 1.58 KB
/
ex002.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Exercício #02 | Simulado JS (04/2016)</title>
<style>div { margin: 2px; }</style>
</head>
<body>
<p>Esse é um parágrafo!</p>
<p>Esse é outro parágrafo!</p>
<p>Eita! Mais um.</p>
<div>Tá, agora é uma div!</div>
<div>Outra div.</div>
<div>E mais uma div, PORQUE SIM!</div>
<br><br>
<button id="b1">AGORA CLICA AQUI! :)</button>
<script>
/*
Exercício #02
=============
Implemente uma função que é disparada ao clicar num botão de id b1.
Esta função faz com que os elementos p fiquem com o fundo azul e as divs com o fundo vermelho.
Use apenas querySelectorAll. */
function ex02(){
var botao = document.querySelector('#b1');
botao.onclick = function(){
var ps = document.querySelectorAll('p');
var divs = document.querySelectorAll('div');
for (var i=0; i<ps.length; i++){
ps[i].style.backgroundColor = "#00f";
}
var x=0;
while( x < divs.length ){
divs[x].style.backgroundColor = "#f00";
x++;
}
};
}
ex02();
</script>
</body>
</html>