-
Notifications
You must be signed in to change notification settings - Fork 220
/
events.js
38 lines (28 loc) · 1.04 KB
/
events.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
// Don't change or delete this line! It waits until the DOM has loaded, then calls
// the start function. More info:
// https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded
document.addEventListener('DOMContentLoaded', start)
function start () {
// The first example is done for you. This will change the background colour of the first div
// when you mouse over it.
one()
// Your turn! Create a new function called `two`, then call it from here.
}
function one () {
// First, we have to find the element:
var one = document.getElementById('one')
// Next, we add an event listener to it:
one.addEventListener('mouseenter', makeBlue)
// Finally, we add one to make the colour white again
one.addEventListener('mouseleave', makeWhite)
}
// CREATE FUNCTION two HERE
// CREATE FUNCTION three HERE
// CREATE FUNCTION four HERE
// Changes the background color of event's target
function makeBlue (evt) {
evt.target.style.backgroundColor = 'blue'
}
function makeWhite (evt) {
evt.target.style.backgroundColor = 'white'
}