0
 var rowCount = 0;
 var trCount;

  // Set start each at second tr
  $('#list tr').each(function(index, tr) {
    // Count
    rowCount++;

    // Create tr
    trCount = $('<tr/>');

    // Create row number 1,2,3
    trCount.append("<td>" + rowCount + "</td>");

    // Append tr to display table
    tableContent.append(trCount);
  });

i am using the to create tr to my table , but my intention here is there will be different background-color between odd and even tr number , so how do i do this ?

something like this

$("tr:odd").css("background-color", "#E5E5E5");
$("tr:even:gt(0)").css("background-color", "#c7d4e5");

how do i append different back ground color when creating <tr>.

Andreas
  • 21,535
  • 7
  • 47
  • 56
dee cheok
  • 257
  • 3
  • 17

1 Answers1

2

You can do this in pure CSS and it will apply no matter how much javascript you throw at it.

tr:nth-of-type(even) {
    background-color:#E5E5E5;
}
tr:nth-of-type(odd) {
    background-color:#c7d4e5;
}
ntgCleaner
  • 5,865
  • 9
  • 48
  • 86