-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
38 lines (37 loc) · 2.01 KB
/
index.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 lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Arrow Functions</title>
</head>
<body id="body">
<h1>My Boring Website</h1>
<p id="paragraph">
This website is boring, with very little CSS.
However, we really just care about the javascript.
For example, if you click <button id="button">this button</button>, the background of this paragraph tag will change to blue.
</p>
<p>We also have a <button id="alert">alert</button> button that will grab the text from the input below and show it in a popup.</p>
<div>
<input type="text" id="popup-input">
</div>
<p>
We just like random interactivity in the site, including a fun effect if you hover over <span id="hover-this"> <b>this.</b></span>
</p>
<p id="change-this">
Another task: This should be another feature.
I want to click anywhere in this paragraph tag and I want to be able to change the background color to whatever is in this input: <input id="background-input" type="text"/>.
</p>
<script>
document.getElementById("button").onclick = () =>{ setBackgroundColorById("paragraph", "blue");}
document.getElementById("alert").onclick = () => {alert(document.getElementById("popup-input").value);}
document.getElementById("hover-this").onmouseover = () => {setBackgroundColorById("body", "red");}
document.getElementById("hover-this").onmouseout = () => {setBackgroundColorById("body", "white");}
const getValueFromId = (id) => {return document.getElementById(id).value;}
const setBackgroundColorById = (id, color) => {document.getElementById(id).style = "background-color: " + color;}
document.getElementById("change-this").onclick = () => {setBackgroundColorById("change-this", document.getElementById("background-input").value) ;}
</script>
</body>
</html>