Gaspa79 Gaspa79 - 1 year ago 75
CSS Question

Remove a table row but keep the CSS alternate rows format

So I have a table that has an alternating format for rows (let's say grey and white). I'm deleting a row with the tr.remove() jquery function, and of course the css of the rows over/under it will not change, and they will keep their odd/even styles. Basically:

Before Deletion After Deletion

grey grey
white white
grey white
white grey

Is there any way to quickly force the table to "refresh" the styles? Or do I have to apply them manually using jquery?

Thanks a lot!

Answer Source

So do the styling with CSS instead of using odd/even classes/ hardcoding values.

document.querySelector("tbody").addEventListener("click", function(e) {
    var td =,
        tr = td.parentNode;
    tr:nth-child(even) {
      background-color: #FFF;
    tr:nth-child(odd) {
      background-color: #CCC;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download