I have an html table similar to this:
<table>
<tr>
<td>1</td>
<td>Some text...</td>
</tr>
<tr>
<td>2</td>
<td>Some text...</td>
</tr>
<tr>
<td>3</td>
<td>Some text...</td>
</tr>
<tr>
<td>1</td>
<td>Some text...</td>
</tr>
<tr>
<td>1</td>
<td>Some text...</td>
</tr>
<tr>
<td>2</td>
<td>Some text...</td>
</tr>
<tr>
<td>3</td>
<td>Some text...</td>
</tr>
</table>
The cells in the first column contain a numerical value of 1, 2, or 3.
Im looking for a neat way to convert this value to something more “graphical” using a client-side approach like CSS (preferably) or jQuery. For example, instead of “1,” the contents of the cell should appear as an icon or dot with a red color. Just setting the background color will also be fine.
UPDATE:
Thanks for all the suggestions. It seems that it was just the Every method from jQuery, which I was missing. :)
Here is my last code. I wrapped it in a separate function, which is called on the finished document even after updating the table.
function fnTransformIcons()
{
var color;
$("td.Icon").each(function() {
var value = $(this).html();
switch (parseInt(value))
{
case 0 : color = 'white'; break;
case 1 : color = 'red'; break;
case 2 : color = 'green'; break;
case 3 : color = 'yellow'; break;
}
$(this).css("backgroundColor", color);
});
}