-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor3.html
37 lines (37 loc) · 1.33 KB
/
color3.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Colors 3</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
//new es6 way to define function
//arrow way
document.addEventListener('DOMContentLoaded', () => {
document.querySelector('#color-change').onchange = function() {
document.querySelector('#hello').style.color = this.value;
}
});
//using => fat arrow way the this keyword would not select the select
//rather it would select the whole window
//so while binding elements to this keyword
//function should be defined in the traditional way
//function()
// document.addEventListener('DOMContentLoaded', () => {
// document.querySelector('#color-change').onchange = () => {
// document.querySelector('#hello').style.color = this.value;
// }
// });
</script>
</head>
<body>
<h1 id="hello">Hello!</h1>
<select id="color-change">
<option value="Black">Black</option>
<option value="Red">Red</option>
<option value="Blue">Blue</option>
<option value="Green">Green</option>
</select>
</body>
</html>