Dynamic CSS Switching using Javascript...
- Started
- Last post
- 5 Responses
- MrWhite
I'm looking for a nonPHP version of css switching using javscript and based on days of the week only (Monday, Tuesday, Wed. etc.). I would prefer to not switch the css but rather a background image being called from CSS. Is this possible rather than just switching css files?
I don't want to load this on the body tag, but from a DIV tag.
Any helpis appreciated.
Thanks!
- Vicentvangogh0
Try here:
- Nathan_Adams0
Why not php?
It would be easier to create a php script to choose the background, and then link to that in the css instead of a single jpg.
- neverblink0
yes, pretty simple actually.. (I'll asume it's the background image of the body you'll want to switch)
// get what day of the week it is
var d=new Date();switch(d){
case(0): // sunday
document.body.style.backgroundIm... = "url('sunday.jpg')";
break;
case(1): // monday
document.body.style.backgroundIm... = "url('monday.jpg')";
break;
// etc. for the rest of the days of the week.
}
- neverblink0
little error in above script:
var d = new Date();
d = d.getDay(); // <-- added this line