Link to home
Start Free TrialLog in
Avatar of roger v
roger vFlag for United States of America

asked on

Setting color of <td> using DHTML - question

Hi Experts,

I have a coldfusion page that displays records from a database. Some of these records might be empty, in which case the <td> element is empty with no text in it. I need a way to recognize if a <td> element is empty (does not have any data from the database) and then set the color of that td to red.

I could do this using  a bunch of if statements in coldfusion, but I was wondering if there is a more efficient way of doing this with dhtml/css. I found something online that mentioned a css pseudo class :contains to check the innerText, but I've never done this before and your guidance is needed. tia,

roger
SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of s8web
s8web

Oops, should be not len. My bad.

<tr>
      <td<cfif not len(tablecolumn)> style="background:red;"</cfif>>Content</td>
</tr>
Avatar of roger v

ASKER

@level9 & @s8web:

That is the issue - I have over a hundred <td>'s. I'll have to put a cfif on all hundred of them. Is there a way to do it server side in one central location instead of every single <td>?

@gurvinder:

Does that code go in between <style type="text/css"></style> or <script></script> tags?
its a script so it will go in <script></script> tags
>> Is there a way to do it server side in one central location instead of every single <td>?
You could extend how CF parses the code by the might get a bit complicated. A simple solution to start might be just to use 'find and replace' in your editor.
Excuse my grammar/typo above it should read, "You could extend how CF parses the code but that might..."