So, actually manipulating the properties of your class selector can be pretty hairy (see PPK's article on the subject for details).
If you're okay with just changing the style.color property of the DOM elements with a particular class name, then you could use something like this: function changeColor(className, color) {
var elems = document.body.getElementsByTagName('*');
for (var i = 0, len = elems.length; i < len; i++ ) {
if (elems[i].className == className) {
elems[i].style.color = color;
}
}
}
changeColor('contentbody', '#000');
This makes a sketchy assumption, though: that className is the only css class assigned the the elements in question. However, pasting this code into Firebug and running it on an article like Learn Cocoa appears to do the trick.
A more robust recommendation would be to use something like prototype's document.getElementsByClassName function instead.
by Adam Luikart — Apr 27
If you're okay with just changing the style.color property of the DOM elements with a particular class name, then you could use something like this:
function changeColor(className, color) { var elems = document.body.getElementsByTagName('*'); for (var i = 0, len = elems.length; i < len; i++ ) { if (elems[i].className == className) { elems[i].style.color = color; } } } changeColor('contentbody', '#000');
This makes a sketchy assumption, though: that className is the only css class assigned the the elements in question. However, pasting this code into Firebug and running it on an article like Learn Cocoa appears to do the trick.
A more robust recommendation would be to use something like prototype's document.getElementsByClassName function instead.