I have the following code set up in my footer which adds a class of 'day' during the time specified.
function setTimeStyles() {
var currentTime = new Date().getHours();
if(currentTime > 5 && currentTime < 17) {
document.body.className = 'day';
}
}
$(document).ready(function() {
setTimeStyles();
});
The problem is when the class gets added, it gets rid of the other classes already in place. For example, without the 'day' class added, my body tag would be:
<body class="home">
But when the 'day' class is added, my body tag turns into:
<body class="day">
I'd like it so that the 'day' class gets added to what's already there like this:
<body class="home day">
How can I go about doing this?
In jQuery you can do
Have you tried replacing
with
I don't know how jquery adds a class, but you may want to be sure it is added (or moved) to the end of any existing list, giving it precedence in any collisions.