I am trying to use query to set color of alternate rows of a html table. But every time I add a new row query switches the color of the whole table. Here is the Javascript code I am using:
var alternate = true;
function addRow(data) {
if(alternate){
$("table.live_feed").find('tbody.main').prepend(data).css("background", "#f1f1f1");
alternate = false;
}else{
$("table.live_feed").find('tbody.main').prepend(data).css("background", "white");
alternate = true;
}
}
PS: I looked as some similar questions on Stack Overflow where they change the color of odd or even rows. I do not want to change the color of rows that are already present, I only want to change the color of new rows being added.