Searching single table column with jQuery

In Codeigniter 1.7.2 there is no way to change the style of an individual cell with the Table class, this is not good and everyone is much looking forward to 2.0 where this sort of magic is apparently going to be included (go to this page and search for “individual cells”). So, say you have a table that contains specific values in some cells that need extra attention – if the table contains no colspan or rowspan then you’re emphatically in luck and can do the following trick with jQuery without custom id tagging of your content:


$('td:nth-child(10)').each(function () { // search 'Deposit'
content = $(this).text();
if (content.indexOf("No") != -1) {
$(this).css('background-color','#ff0000');
} else if (content.indexOf("Waiting") != -1) {
$(this).css('background-color','#fef612');
} else if (content.indexOf("Yes") != -1) {
$(this).css('background-color','#0abd09');
}
});

That will select the 10th column and search it for specific value and change the container cells depending thereupon, result can be seen in screenshot. Ah yes. Side-note: of course you would need to wrap your jQuery code in the pre-requisite $(document).ready(function() and so forth (Google is our mutual friend).

Resources used in connection to above snippet:
http://www.javascripttoolbox.com/temp/table_cellindex.html
http://tylermuth.wordpress.com/2008/12/17/jquery-selectors-will-change-your-life/