Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery alternate table row colors for a specific table

i have two tables. <table id='1'></table> and <table id='2'></table>. When i put this code:

$(document).ready(function()
{
  //for table row
  $("tr:even").css("background-color", "#F4F4F8");
  $("tr:odd").css("background-color", "#EFF1F1");

});

Both the tables got it alternate row colors, which i dont want, i want only to color the table with id=2. how it can be accomplished?

like image 757
tarique Avatar asked May 24 '10 13:05

tarique


1 Answers

Modify your code like:

$(document).ready(function()
{
  $("table#id2 tr:even").css("background-color", "#F4F4F8");
  $("table#id2 tr:odd").css("background-color", "#EFF1F1");
});

This assumes you have table with id set to id2 eg:

<table id="id2">
like image 80
Sarfraz Avatar answered Nov 15 '22 18:11

Sarfraz