Jquery: cloning a table and its first row

AndyT

I have a standard table structure like this:

<table id="test">
  <th>...</th>
  <tr><td>one thing</td></tr>
  <tr><td>another</td></tr>
  ...
  ...
</table>

I know how to clone the entire table, or the nth row of a table, but what I need is the whole thing, EXCEPT the 2nd, 3rd, 4th etc row of the table, in other words:

<table id="test">
  <th>...</th>
  <tr><td>one thing</td></tr>
</table>

Ideas please?

Karl-André Gagnon

"I know how to clone the entire table..."

Then do that, clone the entire table, then remove what you dont need.

A trick to select everything except first child is to use *+*. + selector in css mean the matching element on right side next to the element on the left side.

In the end, you can use that :

var $clone = $('#test').clone().find('tr+tr').remove().end();

$clone will then be your clone table with only the first row.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Toggle cloning of table row to another table with jQuery

From Dev

Toggle cloning of table row to another table with jQuery

From Dev

jQuery cloning of table row breaks button

From Dev

Cloning closest table row

From Dev

Probleme cloning row in jQuery

From Dev

Jquery - select2 dropdown disabled when cloning a table row

From Dev

why is jquery first().clone() in a table still cloning multiple elements?

From Dev

jQuery: skipping first table row

From Dev

jQuery DataTables clear table except the first row

From Dev

Jquery add css class to the first row of a table

From Dev

How to copy first row of a table using Jquery?

From Dev

Jquery add css class to the first row of a table

From Dev

jQuery - Find an integer value in a table row and alert the first column of the row

From Dev

Jquery : Hide first row of all the tables except first table

From Dev

jquery to get each and every row of table and rename its name attribute

From Dev

jQuery select both first and last row of a table in single selective statement

From Dev

How to select the all table columns in a row but the first with jQuery?

From Dev

Jquery loop through all the rows in a table without first row

From Dev

Loop through each column of first row in table with JQuery

From Dev

Jquery loop through all the rows in a table without first row

From Dev

Jquery star rating only showing on first row and not all rows in table

From Dev

jQuery - Check empty inputs works but only checks first row in table

From Dev

Trying to change a row of a user filled table with jquery only works on first row

From Dev

Cloning an array with its content

From Dev

Generating table with jquery row by row?

From Dev

MySQL: Always select row with first of its kind

From Dev

how to select first row in table

From Dev

Unable to edit first Row in table

From Java

Add table row in jQuery

Related Related

  1. 1

    Toggle cloning of table row to another table with jQuery

  2. 2

    Toggle cloning of table row to another table with jQuery

  3. 3

    jQuery cloning of table row breaks button

  4. 4

    Cloning closest table row

  5. 5

    Probleme cloning row in jQuery

  6. 6

    Jquery - select2 dropdown disabled when cloning a table row

  7. 7

    why is jquery first().clone() in a table still cloning multiple elements?

  8. 8

    jQuery: skipping first table row

  9. 9

    jQuery DataTables clear table except the first row

  10. 10

    Jquery add css class to the first row of a table

  11. 11

    How to copy first row of a table using Jquery?

  12. 12

    Jquery add css class to the first row of a table

  13. 13

    jQuery - Find an integer value in a table row and alert the first column of the row

  14. 14

    Jquery : Hide first row of all the tables except first table

  15. 15

    jquery to get each and every row of table and rename its name attribute

  16. 16

    jQuery select both first and last row of a table in single selective statement

  17. 17

    How to select the all table columns in a row but the first with jQuery?

  18. 18

    Jquery loop through all the rows in a table without first row

  19. 19

    Loop through each column of first row in table with JQuery

  20. 20

    Jquery loop through all the rows in a table without first row

  21. 21

    Jquery star rating only showing on first row and not all rows in table

  22. 22

    jQuery - Check empty inputs works but only checks first row in table

  23. 23

    Trying to change a row of a user filled table with jquery only works on first row

  24. 24

    Cloning an array with its content

  25. 25

    Generating table with jquery row by row?

  26. 26

    MySQL: Always select row with first of its kind

  27. 27

    how to select first row in table

  28. 28

    Unable to edit first Row in table

  29. 29

    Add table row in jQuery

HotTag

Archive