I used the code provided as an answer found on the question Here . very useful for me. But I am stucked in something really strange.
I use ajax to get some values from database and then save them in a dictionary etc. then with this code I check the values if are equal with the ones coming from database and change the tables cell color respectively.Everything seems fine except from " The first and always the first record that comes out from the database is not changing to the correct color, no matter how many records are there, The color should be #000 and not #ffff99". Both values that I am comparing are 12:00.
That seems to be pretty crazy because If I remove the else statement from the code. Everything works fine. But I need the else statement to do some other important stuff and by the way I don't think that not using the else statement is a good practice xD.
Below is my code.
for(const [key, value] of Object.entries(data))
{
var table = document.getElementById('table'),rows = table.rows, rowcount = rows.length, r,cells, cellcount, c, cell;
for( r=0; r<rowcount; r++)
{
cells = rows[r].cells;
cellcount = cells.length;
for( c=0; c<cellcount; c++)
{
cell = cells[c];
var text = (cell.textContent || cell.innerText);
if( text == key.substring(0,5))
{
cell.style.backgroundColor="#000";
break;
}
else
{
cell.style.backgroundColor="#ffff99";
}
}
}
}