forked from wbruno/boas-praticas-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaleta.js
47 lines (37 loc) · 1.17 KB
/
paleta.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
(function(window, document, undefined){
'use strict';
var $body = document.querySelector('body'),
$btns = document.querySelector('#btns'),
i = 0,
max = $btns.length,
classe_antiga;
$btns.addEventListener('click', function(event){
var $this = event.target;
if($this.tagName === 'INPUT') {
$body.classList.remove('black');
$body.classList.remove('blue');
$body.classList.remove('red');
$body.classList.remove('yellow');
$body.classList.remove('pink');
$body.classList.remove('white');
$body.classList.remove('green');
$body.classList.remove('gray');
$body.classList.add($this.getAttribute('data-class'));
}
});
// não mexer, mágica
// while(max--) {
// var $this = $btns[max];
// $this.addEventListener('click', function(){
// $body.classList.remove('black');
// $body.classList.remove('blue');
// $body.classList.remove('red');
// $body.classList.remove('yellow');
// $body.classList.remove('pink');
// $body.classList.remove('white');
// $body.classList.remove('green');
// $body.classList.remove('gray');
// $body.classList.add(this.getAttribute('data-class'));
// });
// }
}(window, document));