This JavaScript code can be used to colour code cells in a Sharepoint list.
The script works by looking at all the table cells on a page (ie <td> elements) and identifying the ones using the "ms-vb2" class. These are the cells used in standard lists.
It then checks the content of the cell and if it matches one of the conditions it changes the background colour of that cell.
In the example it looks for cells containing the colours "Green", "Amber" or "Red" and sets the background colour appropriately.
This could be modified to change other style sheet properties such as text colour, font weight etc.
<script type="text/javascript" language="javascript">
var x = document.getElementsByTagName("TD");
var i=0;
for (i=0;i<x.length;i++)
{
if (x[i].className=="ms-vb2") //find the cells styled for lists
{
if (x[i].innerHTML=="Green") //find the data to use to determine the colour
{
x[i].style.backgroundColor="Green"; // set the colour
}
if (x[i].innerHTML=="Amber")
{
x[i].style.backgroundColor="Yellow"; // set the colour
}
if (x[i].innerHTML=="Red")
{
x[i].style.backgroundColor="Red"; // set the colour
}
}
}
// Finished updating cells
</script>
$("img[src*='minus.gif']:visible").parent().click();
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"
type="text/javascript"></script>