How to change table row ID dynamically based on the row delete?

Maniram

I have a table with 5 rows, My requirement is to add/delete table row dynamically..at the same time to handle the table row id dynamically.

Please find my table here:

<table>
<tbody>
    <tr id='1'>
        <td>Row 1</td>
    </tr>
    <tr id='2'>
        <td>Row 2</td>
    </tr>
    <tr id='3'>
        <td>Row 3</td>
    </tr>
    <tr id='4'>
        <td>Row 4</td>    
    </tr>
    <tr id='5'>
        <td>Row 5</td>    
    </tr>
</tbody>

I am using jquery below code for deletion. For ex. I am deleting second row, then the row id 2 has been deleted and row id should be interchange dynamically.

Find my script here:

var index = $(this).closest('tr').index();
if (index > 0) {
     $(this).closest('tr').remove();
}

Any help on this?

Balachandran

Fiddel Demo

use nextAll method to select all next element .. to change the id .it works effectively

 $("tr").click(function () {
        $(this).nextAll().each(function () {
            var id = $(this).prop("id", function (index, idvalue) {
            return idvalue - 1;
           });
      });
        $(this).remove();
  });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to change table row ID dynamically based on the row delete?

From Dev

How to hide table row dynamically on dropdown change?

From Dev

How to hide table row dynamically on dropdown change?

From Dev

Delete a dynamically added table row

From Dev

Delete a dynamically created table row

From Dev

How to dynamically change the template in aurelia / click to edit table row?

From Dev

How to dynamically change the template in aurelia / click to edit table row?

From Dev

To delete a row dynamically from a table using javascript

From Dev

Change dynamically generated table row background color

From Dev

Change dynamically generated table row background color

From Dev

Change a table row dynamically using JQuery/Javascrpit

From Dev

How to change table row color based on 3 condition in angularJs

From Dev

How to change Table row colour based on content using Javascript

From Dev

delete a row from table based on a specific association

From Dev

delete a row from table based on a specific association

From Dev

How to get table row by id and then change it's value / html

From Dev

AJAX Delete row in table with PHP id selected

From Dev

jQuery delete table row by dynamic id

From Dev

Hide clicked row based on row.id using Bootstrap Table

From Dev

How to delete a row based on its index?

From Dev

How to delete row in html based on cell value

From Dev

How to delete a row in SQL based on a NULL condition

From Dev

Delete dynamically-generated table row using jQuery

From Dev

delete table row dynamically using jQuery in asp.net mvc

From Dev

Delete Row in a Table Based on a Lookup Value from Another Table

From Dev

How to delete row which contains specific id as text if I have table id tag?

From Dev

How to delete the table row on button click

From Dev

How to delete row from table column javafx

From Dev

How to delete a row in a table using jQuery?

Related Related

  1. 1

    How to change table row ID dynamically based on the row delete?

  2. 2

    How to hide table row dynamically on dropdown change?

  3. 3

    How to hide table row dynamically on dropdown change?

  4. 4

    Delete a dynamically added table row

  5. 5

    Delete a dynamically created table row

  6. 6

    How to dynamically change the template in aurelia / click to edit table row?

  7. 7

    How to dynamically change the template in aurelia / click to edit table row?

  8. 8

    To delete a row dynamically from a table using javascript

  9. 9

    Change dynamically generated table row background color

  10. 10

    Change dynamically generated table row background color

  11. 11

    Change a table row dynamically using JQuery/Javascrpit

  12. 12

    How to change table row color based on 3 condition in angularJs

  13. 13

    How to change Table row colour based on content using Javascript

  14. 14

    delete a row from table based on a specific association

  15. 15

    delete a row from table based on a specific association

  16. 16

    How to get table row by id and then change it's value / html

  17. 17

    AJAX Delete row in table with PHP id selected

  18. 18

    jQuery delete table row by dynamic id

  19. 19

    Hide clicked row based on row.id using Bootstrap Table

  20. 20

    How to delete a row based on its index?

  21. 21

    How to delete row in html based on cell value

  22. 22

    How to delete a row in SQL based on a NULL condition

  23. 23

    Delete dynamically-generated table row using jQuery

  24. 24

    delete table row dynamically using jQuery in asp.net mvc

  25. 25

    Delete Row in a Table Based on a Lookup Value from Another Table

  26. 26

    How to delete row which contains specific id as text if I have table id tag?

  27. 27

    How to delete the table row on button click

  28. 28

    How to delete row from table column javafx

  29. 29

    How to delete a row in a table using jQuery?

HotTag

Archive