The <span id="date">
doesn't exist when the script is executed. You can put it in an onload
handler to fix this:
<script>
onload = function() {
document.getElementById("date").innerHTML = Date();
};
</script>
That will run the script sometime after the entire DOM is ready. Of course, you can handle DOMContentLoaded
to run the code immediately when the DOM is ready, and not after its contents have also loaded, but the other (really easy) way is to put your script before the closing </body>
tag:
<html>
<head>
<title>Date Test</title>
</head>
<body>
<p>Today's date is <span id="date"></span></p>
<script>
document.getElementById("date").innerHTML = Date();
</script>
</body>
</html>