The only good style of defining colors is CSS. Therefore, the only good way to do this in JavaScript is changing or adding the style of the element. And one of the most convenient way of doing this is using jQuery:
http://en.wikipedia.org/wiki/JQuery[
^],
http://jquery.com/[
^].
You can use the jQuery
.addClass
,
.removeClass
or
.toggleClass
methods:
myElement = $("#myElement");
className = "yellowBackground";
myElement.addClass(className);
myElement.removeClass(className);
myElement.toggleClass(className);
Naturally, you would need the correspondent classes in CSS:
.yellowBackground { background-color: yellow; }
Please see:
http://api.jquery.com/addClass/[
^],
http://api.jquery.com/removeClass[
^],
http://api.jquery.com/toggleClass/[
^].
Learning jQuery is easy and a kind of fun. Start here:
http://docs.jquery.com/Tutorials[
^],
http://docs.jquery.com/Tutorials:How_jQuery_Works[
^].
—SA