The document style sheets object is all of the styles on the web page and is index within an array manor. For example
styleSheet = document.styleSheets[
But since the two main browsers (Internet Explorer and also Firefox) deal with the css rules within this object with a different reference (IE = rules and FF = cssRules).
if (styleSheet.cssRules) cssRule = styleSheet.cssRules; // Firefox else if (styleSheet.rules) cssRule = styleSheet.rules; // IE
cssRule = document.getElementById(style)
And then once the object of the style is obtained with both functions can just alter the style of the object with the same code.
if (cssRule.style.backgroundColor == colour) cssRule.style.backgroundColor = colour2; else cssRule.style.backgroundColor = colour;
Here is the full code
Change this style