I want to add alternating colors to rows in a table, but instead of changing color every other row I want to switch color when the data in the first column changed compare to the row above. For example in the table below, the first two row would have the same color since the first fields are both “1”, and the third row would have a different color. I’m looking for a solution without third-party libraries like jquery.
1 | A
1 | B
2 | C
3 | D
4 | E
Here’s one way of doing it: jsfiddle demo