-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise1.html
More file actions
46 lines (42 loc) · 1022 Bytes
/
exercise1.html
File metadata and controls
46 lines (42 loc) · 1022 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Exercise #1: Changing text</title>
<style>
#mydiv {
width: 300px;
height: 50px;
line-height: 50px; /* for vertical alignment of text */
text-align: center;
border: 1px solid black;
background-color: yellow;
font-size: 2em;
font-weight: bold;
}
</style>
</head>
<body>
<div id="mydiv" >Hello world</div>
<script>
// my div is an object and obj have method
var mydiv =document.getElementById("mydiv");
// call functions
// onmouseover is a event for mydiv obj
mydiv.onmouseover = function () {
mouseOver();
};
mydiv.onmouseout = function () {
mouseOut();
};
// declare functions
function mouseOver() {
// innerhtml method to change html elem content
mydiv.innerHTML = "Can I help you?";
}
function mouseOut() {
mydiv.innerHTML = "Hello world!";
}
</script>
</body>
</html>