I would like to make the current date and time in a div element in html update automatically. Is there a way I can do this? I do know that I can update it by clicking on a button.
Advertisement
Answer
You can do this:
JavaScript
x
13
13
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<title>Page Title</title>
5
</head>
6
<body>
7
<div id="time"></div>
8
<script>
9
setInterval(function(){ document.getElementById('time').innerText = new Date()}, 1000);
10
</script>
11
</body>
12
</html>
13