I have a table whose TD’s contain ordinary text. Is there a way to style (e.g. set the background color) on a TD according to the TD’s contents? For example, I might want GO to have a green background, while RED should have a red background.
I’ve tried these without success:
td[innerText='GO']
td[innerHtml='GO']
td[outerText='GO']
Of course I could set a class or an explicit style for each TD according to its contents, but I would prefer to avoid that.
You’ll have to use javascript to check the contents, and then alter the style of your
tdtag.You may have a function in a
script.jsfile:And then you use this function in your
tabletag, like:Notice the comparison is made with both
tds[i].textContentandtds[i].innerText, as the later is required for IE.