Skip to content Skip to sidebar Skip to footer

Business Open/closed Text On Page According To Time

I must have tried a 100 variations of this code and can't seem to get it right. I feel like I'm walking further off the playing field. I want to display a message on our pages tha

Solution 1:

Try this (see the jsfiddle):

var today = newDate(),
    open = "We're open today from 9am - 5pm",
    closed = "We're closed and will open again tomorrow 9am - 6pm",
    display = document.getElementById('display');

if (today.getHours() >= 9 && today.getHours() < 18) {
    display.innerHTML = open;
} else {
    display.innerHTML = closed;
}

HTML:

<div id="display"></div>

I assume your problem was that it was displaying "open" or "closed" in the div, when it should be displaying either "We're open today from 9am - 5pm" or "We're closed and will open again tomorrow 9am - 6pm". The issue was that you were referencing the variables open and closed as strings.

Post a Comment for "Business Open/closed Text On Page According To Time"