If I'm trying to affect an HTML element with a script (getElementById) it only works if the script comes after the element. Isn't javascript code usually all at the top of the HTML doc? For example:
Why does this work:
<!DOCTYPE html>
<html>
<body>
<p id="helloMessage"> </p>
<script>
document.getElementById("helloMessage").innerHTML = "Hello, World!";
</script>
</body>
</html>
but this does not
<!DOCTYPE html>
<html>
<body>
<script>
document.getElementById("helloMessage").innerHTML = "Hello, World!";
</script>
<p id="helloMessage"> </p>
</body>
</html>