Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9026695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:35:06+00:00 2026-06-16T06:35:06+00:00

I have a table whose TD’s contain ordinary text. Is there a way to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:35:08+00:00Added an answer on June 16, 2026 at 6:35 am

    You’ll have to use javascript to check the contents, and then alter the style of your td tag.

    You may have a function in a script.js file:

    function tdStyle(current_table) {
    
        var tds = current_table.getElementsByTagName("td");
    
        for (i = 0; i < tds.length; i++) {
    
            if (tds[i].textContent == "string1" || tds[i].innerText == "string1") {
                tds[i].style.backgroundColor = "green";
            } else if (td_tag.textContent == "string2" || tds[i].innerHTML == "string2") {
                tds[i].style.backgroundColor = "red";
            } else if (td_tag.textContent == "string3" || tds[i].innerHTML == "string3") {
                tds[i].style.backgroundColor = "blue";
            }
    
        }
    
    }
    

    And then you use this function in your table tag, like:

    <table onload="tdStyle(this);">
    <tr><td>...</td></tr>
    <tr><td>...</td></tr>
    <tr><td>...</td></tr>
    ...
    </table>
    

    Notice the comparison is made with both tds[i].textContent and tds[i].innerText, as the later is required for IE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table whose cells contain labels. Whenever I dequeue a reusable cell,
I have a data table whose defaultview.sort is already set, and the datatable is
I have a table whose rows contain radio button groups like so: <td class=usegsm>
I have an HTML table whose cells contain, among other things, spans, like this:
i have a table whose structure is <table> <tr> <td> <input type=text id=field_1 />
I have a database table whose fields contain latitude and longitude coordinates of positions.
I have a table whose columns are varchar(50) and a float . I need
I have a table whose primary key is a column named St_ID . I
I have a table with a column whose values come from an Enumeration. I
I have a table , half of whose cells are rowspan=2 and the other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.