I'm writing a function to toggle the body background between light and dark, both a tiled image and a backup background color. In index.html, my body tag is:
<body style="background-color:#111111; background-image:url('dvsup.png');">
It seems I have to put the styles I want to change through javascript within index.html, or it doesn't work. At least, not in IE9.
Here's the code snippet in my script.js:
function _(el){return document.getElementById(el);}
// this just acts as shorthand
//here's the problematic function:
function light(){
_("lights").className=
(_("lights").className==="deselected")?
"selected":"deselected";
document.body.style.backgroundColor=
(document.body.style.backgroundColor==="#111111")?
"#EFEFEF":"#111111";
document.body.style.backgroundImage=
(document.body.style.backgroundImage==="url('dvsup.png')")?
"url('dvsupw.png')":"url('dvsup.png')";}
This all works perfectly in IE9, on the work computer. When a button calls "light()", it changes the background image and color, and the class of the button itself. In Chrome and Chromium (at home), it falls apart. The changing of the className from "selected" to "deselected" works, but the rest doesn't.
Oddly, if I change the "===" identifiers to "=" assigners for "style.backgroundColor" and "style.backgroundImage", in Chrome the background image will change to "dvsupw.png" upon calling "light()", but won't change back.
Am I missing something obvious? How come this isn't working?
And if I haven't been clear, tell me.
Thanks. Al.