I am using NGINX. I want to display the current time as an easy way of practicing. I set this in a JavaScript variable. So far, I have a little bit of HTML code.
<!DOCTYPE html>
<html>
<head>
<title>???</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
<script type="text/javascript">
function myFunction() {
var d = new Date()
var n = d.getTime()
document.getElementById('current-time').innerHTML = n
}
</script>
</head>
<body onload="myFunction">
<h1>???</h1>
<p>This is the current time.</p>
<p>
<u>
<i>
Current Date and Time is
<span id="current-time"></span>
</i>
</u>
</p>
</body>
</html>
I don’t understand why this isn’t working, I have looked in Stack Overflow a lot and this is what they say to do. There are no errors printing in the console, and all the page says is “Current Date and Time is”, and nothing happens with the <span id="current-time">
.
`](https://stackoverflow.com/q/191157/4642212); there are several approaches to “fix” this, but do stick with best practices. Before this gets lost, I’ll ask again: you say _“I have looked in Stack Overflow a lot and this is what they say to do”_ — Where, on Stack Overflow have you seen `onclick='myFunction'` being recommended?
– Sebastian Simon Mar 23 '21 at 01:05