I tried that and it didn't work. if I remove the DOM changes and replace them with an alert the condition appears to execute.
Do I need to pass in the DOM element I am trying to change and then return an updated one, or will the function do that anyway?
First let's start with the logic of your if statement:
if ((h <= 5) && (h >=18))
this will always evaluate to false because how can some number be less then or equal to 5 and in the same time be bigger then or equal to 18? It can't! You used wrong logical operator!
Recall that when using logical AND (&&) operator both conditions must be true for overall result to evaluate to true and in your case as I already mention above it's not possible. So the first mistake lies here.
The second mistake is section in your code where you are connecting your event handler with the function
window.onload = dynamicBG()
remember that when you are handling events via object's property you never pass set of parentheses to your calling function. So your connection to function should look like this
window.onload = dynamicBG
and your final code should look something like this
// Dynamic Background for HTML5 template based on time of day.
var d = new Date();
var h = d.getHours();
if ((h>=0 && h<=5) || (h>=18 && h<= 23))
document.getElementById("bgText").innerHTML="The BG Should be Day Time";
document.getElementById("bgText").innerHTML="The BG Should be Night Time";
window.onload = dynamicBG;