Resetting zebra style after removing rows from table

blitzmann

I have a table that, with bootstrap, uses :nth-child to style alternating table rows. However, whenever I remove a row with jQuery .hide() the alternating rows break.

HTML:

<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<table id='t1' class="table table-bordered table-striped table-condensed table-hover table-even-widths">
    <thead>
        <tr>
            <th>Heading A</th>
            <th>Heading B</th>
            <th>Heading C</th>
        </tr>
    </thead>
    <tbody>
        <tr id='r1'>
            <td>0</td>
            <td>b</td>
            <td>c</td>
        </tr>
        <tr id='r2'>
            <td>1</td>
            <td>b</td>
            <td>c</td>
        </tr>
        <tr id='r3'>
            <td>2</td>
            <td>b</td>
            <td>c</td>
        </tr>
        <tr id='r4'>
            <td>3</td>
            <td>b</td>
            <td>c</td>
        </tr>
        <tr id='r5'>
            <td>4</td>
            <td>b</td>
            <td>c</td>
        </tr>
    </tbody>
</table>

JS:

$('#r4').hide();

http://jsfiddle.net/saznq/1/

I was wondering if there was an easy way to sort of reset the table with the new configuration. I can always make my own .even and .odd class and filter through the table after every update to remove and reapply the classes, but was hoping for a more elegant solution.

Josh Crozier

Aside from $('#r4').remove();, you could use something like this:

$('#r4').after('<tr></tr>').hide();

jsFiddle example

This hides the element, and adds an empty <tr> element after it, displacing its removal and thereby doesn't disturb the :nth-child styling.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Removing duplicates from Pandas rows

From Dev

MySQL - Removing null value rows from table

From Dev

AngularJS zebra striping for table with hidden rows

From Dev

Removing rows by reference using data.table?

From Dev

Datatables: keep zebra stripes after hiding / showing table rows

From Dev

Removing table rows with jQuery

From Dev

How to disable zebra rows on jquery table

From Dev

After removing an element from array using splice. its not resetting.Is my code has any mistake

From Dev

Removing Rows from array

From Dev

Removing duplicate rows (based on values from multiple columns) from SQL table

From Dev

Adding/Removing rows from a form. Resetting entire form

From Dev

How to avoid crashing Rails app after removing column from table?

From Dev

SQLite: *prevent* PRIMARY KEY value from resetting after delete all rows

From Dev

Removing the selected rows from a DataGridView

From Dev

data.table: removing ALL rows after a condition is met

From Dev

Resetting zebra style after removing rows from table

From Dev

Removing All Rows of a Dynamic Table but First Row

From Dev

Trouble while duplicating and removing table rows

From Dev

Deleting all rows from table, and resetting auto incrementation

From Dev

Nutch, NoSuchElementException error after removing table from Hbase

From Dev

Removing the selected rows from a DataGridView

From Dev

data.table: removing ALL rows after a condition is met

From Dev

Removing empty rows from Table jQuery

From Dev

Removing rows from grouped data after an event has occurred

From Dev

Removing rows from a dataframe by identifying rows to keep

From Dev

Resetting visuals for checked rows in a table via button

From Dev

Removing rows from a table in R

From Dev

Style certain rows from database table in html table

From Dev

Code isn’t executed after removing rows in a table

Related Related

  1. 1

    Removing duplicates from Pandas rows

  2. 2

    MySQL - Removing null value rows from table

  3. 3

    AngularJS zebra striping for table with hidden rows

  4. 4

    Removing rows by reference using data.table?

  5. 5

    Datatables: keep zebra stripes after hiding / showing table rows

  6. 6

    Removing table rows with jQuery

  7. 7

    How to disable zebra rows on jquery table

  8. 8

    After removing an element from array using splice. its not resetting.Is my code has any mistake

  9. 9

    Removing Rows from array

  10. 10

    Removing duplicate rows (based on values from multiple columns) from SQL table

  11. 11

    Adding/Removing rows from a form. Resetting entire form

  12. 12

    How to avoid crashing Rails app after removing column from table?

  13. 13

    SQLite: *prevent* PRIMARY KEY value from resetting after delete all rows

  14. 14

    Removing the selected rows from a DataGridView

  15. 15

    data.table: removing ALL rows after a condition is met

  16. 16

    Resetting zebra style after removing rows from table

  17. 17

    Removing All Rows of a Dynamic Table but First Row

  18. 18

    Trouble while duplicating and removing table rows

  19. 19

    Deleting all rows from table, and resetting auto incrementation

  20. 20

    Nutch, NoSuchElementException error after removing table from Hbase

  21. 21

    Removing the selected rows from a DataGridView

  22. 22

    data.table: removing ALL rows after a condition is met

  23. 23

    Removing empty rows from Table jQuery

  24. 24

    Removing rows from grouped data after an event has occurred

  25. 25

    Removing rows from a dataframe by identifying rows to keep

  26. 26

    Resetting visuals for checked rows in a table via button

  27. 27

    Removing rows from a table in R

  28. 28

    Style certain rows from database table in html table

  29. 29

    Code isn’t executed after removing rows in a table

HotTag

Archive