-
Notifications
You must be signed in to change notification settings - Fork 26.7k
/
simple-ternary.html
29 lines (25 loc) · 820 Bytes
/
simple-ternary.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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Simple ternary operator example</title>
</head>
<body>
<label for="theme">Select theme: </label>
<select id="theme">
<option value="white">White</option>
<option value="black">Black</option>
</select>
<h1>This is my website</h1>
<script>
const select = document.querySelector('select');
const html = document.querySelector('html');
select.addEventListener('change', () => ( select.value === 'black' ) ? update('black','white') : update('white','black'));
function update(bgColor, textColor) {
html.style.backgroundColor = bgColor;
html.style.color = textColor;
}
</script>
</body>
</html>