-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateAColoredClock.html
More file actions
55 lines (46 loc) · 922 Bytes
/
CreateAColoredClock.html
File metadata and controls
55 lines (46 loc) · 922 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
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<title>DOM</title>
</head>
<style>
.hour{
color: red;
}
.min{
color: green;
}
.sec{
color: blue;
}
</style>
<body>
<div id="clock">
<span class="hour">hh</span>:<span class="min">mm</span>:<span class="sec">ss</span>
</div>
<script>
let timerId;
function update() {
let clock = document.getElementById('clock')
let date = new Date();
let hours = date.getHours();
if (hours < 10) hours = '0' + hours;
clock.children[0].innerHTML = hours;
let mins = date.getMinutes();
if (mins < 10) mins = '0' + mins;
clock.children[1].innerHTML = mins;
let secs = date.getSeconds();
if (secs < 10) secs = '0' + secs;
clock.children[2].innerHTML = secs;
}
function clockStart() {
timerId = setInterval(update,1000);
update();
}
function clockStop() {
clearInterval(timerId);
}
clockStart();
</script>
</body>
</html>