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

  • SEARCH
  • Home
  • 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 8950063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:21:56+00:00 2026-06-15T13:21:56+00:00

I’m struggling a bit with a table row colouring issue. I’m seeking some guidance:

  • 0

I’m struggling a bit with a table row colouring issue. I’m seeking some guidance:

Briefly, I can create rows for a table using JS; I’m using JS because I don’t know ahead of time how many rows I need. I’d like to colour certain rows based on data content. I’m using embedded CSS in this way:

// CSS:
.newRow{
    color: #dd0000;
    background-color:#ffd700;
}

// JS:
// create a row in the body of the table
row=document.createElement('tr');
if(resp.items[i].mimeType.indexOf("folder") !== -1){
    row.className = "newRow";
}

What I get in both FF and IE is the text is coloured red but the row background is still white.
Could someone provide insight as to where I’m going off the track?

—edited to add all the code—

Thank you all for the responses. I’ve pasted my code here, but I had to obscure a couple of tokens used in Oauth2 authentication, so I haven’t figured out how to make jsfiddle that runs (working on it).

<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8' />
<style type="text/css">
table.gridTable {
    font-family: verdana,arial,sans-serif;
    font-size:11px;
    color:#333333;
    border-width: 1px;
    border-color: #666666;
    border-collapse: collapse;
}
table.gridTable th {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #dedede;
}
table.gridTable td {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #ffffff;
}


  .newRow
{
  color: #dd0000;
  background-color:#ffd700;
}

    </style>
  </head>
  <body>



    <!--Add a button for the user to click to initiate auth sequence -->
    <button id="authorize-button" style="visibility: hidden">Authorize</button>
    <script type="text/javascript">
      var clientId = '<obscured on purpose>';
      var apiKey = '<obscured on purpose>';
      // To enter one or more authentication scopes, refer to the documentation for the API.
      var scopes = 'https://www.googleapis.com/auth/drive';

      // Use a button to handle authentication the first time.
      function handleClientLoad() {
        gapi.client.setApiKey(apiKey);
        window.setTimeout(checkAuth,1);
      }

      function checkAuth() {
        gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
      }

      function handleAuthResult(authResult) {
        var authorizeButton = document.getElementById('authorize-button');
        if (authResult && !authResult.error) {
          authorizeButton.style.visibility = 'hidden';
          makeApiCall();
        } else {
          authorizeButton.style.visibility = '';
          authorizeButton.onclick = handleAuthClick;
        }
      }

      function handleAuthClick(event) {
        gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
        return false;
      }

      function makeTable(foo){
          alert("Length: " + foo.items.length);
      }

      // Load the API and make an API call.  Display the results on the screen.
      function makeApiCall() {
        gapi.client.load('drive', 'v2', function() {

          var request = gapi.client.drive.files.list ();

          request.execute(function(resp) {

              //
              // number of files
             document.getElementById('numFiles').innerHTML='Number of files ' + resp.items.length;

              //
              // create a table
              var root=document.getElementById('myTable');
              var tbl = document.createElement('table');
              tbl.className='gridTable';

              //makeTable(resp);

              //
              // why do I have to do this?
              tbl.setAttribute("id", "table1");

              //
              // todo: create a table header
              var thead = document.createElement('thead');
              tbl.appendChild(thead);
              var orderArrayHeader = ["Title","Date","Mod by","ID","Mime type","File size","Kind"];
              for(var i=0;i<orderArrayHeader.length;i++){
                    thead.appendChild(document.createElement("th")).
                    appendChild(document.createTextNode(orderArrayHeader[i]));
                }

              //
              // create table body
              var tbo=document.createElement('tbody');
              var row, cell;


              //
              // actually make the table
              for(var i=0;i<resp.items.length;i++){

                  //
                  // create a row in the body of the table
                row=document.createElement('tr');
                if(resp.items[i].mimeType.indexOf("folder") !== -1){

                    row.className = "newRow";
                }

                  //
                  // create columns for this row

                    cell=document.createElement('td');
                    cell.appendChild(document.createTextNode(resp.items[i].title));
                    row.appendChild(cell);

                    cell=document.createElement('td');
                    cell.appendChild(document.createTextNode(resp.items[i].modifiedDate));
                    row.appendChild(cell);

                    cell=document.createElement('td');
                    cell.appendChild(document.createTextNode(resp.items[i].lastModifyingUserName));
                    row.appendChild(cell);

                    cell=document.createElement('td');
                    cell.appendChild(document.createTextNode(resp.items[i].id));
                    row.appendChild(cell);

                    cell=document.createElement('td');
                    cell.appendChild(document.createTextNode(resp.items[i].mimeType));
                    row.appendChild(cell);


                    cell=document.createElement('td');
                    cell.appendChild(document.createTextNode(resp.items[i].fileSize));
                    row.appendChild(cell);

                    cell=document.createElement('td');
                    cell.appendChild(document.createTextNode(resp.items[i].kind));
                    row.appendChild(cell);                  



                  tbo.appendChild(row);

              }

              //
              // now that all the rows have been created, add them to the table body
              tbl.appendChild(tbo);

              //
              // insert the table into the div with ID 'myTable' 
              root.appendChild(tbl);

              //
              // fooling around with table elements
              trows = document.getElementById("table1").rows;
//            alert(trows.length);
              row0 = trows[0];
//            alert(row0.cells.length);
//            myCells = row0.cells;
//            myCells[0].value = "WTF?";
              //
              // list of files
/*             for (i=0; i<resp.items.length; i++) {

                    //
                    // assign values
                    var titulo = resp.items[i].title;
                    var fechaUpd = resp.items[i].modifiedDate;
                    var userUpd = resp.items[i].lastModifyingUserName;
                    var fileID = resp.items[i].id;

                    //
                    // create a list
                    var fileInfo = document.createElement('li');
                    fileInfo.appendChild(document.createTextNode('TITLE: ' + titulo + ' FILE ID: ' + fileID + ' - LAST MODIF: ' + fechaUpd + ' - BY: ' + userUpd));                
                    document.getElementById('content').appendChild(fileInfo);

            }
 */          });        
        });
      }
    </script>
    <script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>    
    <p id="numFiles"></p>
    <div id="content"></div>
    <div id="myTable"></div>
  </body>
</html>

Hi, I tried to upvote Akhil’s answer…it was helpful in gaining more knowledge even though I haven’t solved the problem yet. But I need to have 15 reputation points which I have not yet acquired. So I wanted to thank everyone who chimed in. BTW, same behavior in Chrome.

  • 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-15T13:21:58+00:00Added an answer on June 15, 2026 at 1:21 pm

    You might get this behaviour if you didn’t create the td tags.

    make sure you create the appropriate td tags and add it to your tr element.

    var row=document.createElement('tr');
    var td =document.createElement('td');
    td.innerHTML="aaa";
    row.appendChild(td);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.