Avatar of roger v
roger v
Flag 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
CSSWeb Development

Avatar of undefined
Last Comment
level9wizard

8/22/2022 - Mon
SOLUTION
Gurvinder Pal Singh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Hagay Mandel

ASKER CERTIFIED SOLUTION
level9wizard

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
s8web

Oops, should be not len. My bad.

<tr>
      <td<cfif not len(tablecolumn)> style="background:red;"</cfif>>Content</td>
</tr>
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?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Gurvinder Pal Singh

its a script so it will go in <script></script> tags
level9wizard

>> 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.
level9wizard

Excuse my grammar/typo above it should read, "You could extend how CF parses the code but that might..."
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.