To add a new row at the end of the table, use the following code,
- $(‘#table_id > tbody:last’).append(‘
….
’);
Here, table_id is an id of your table.
You can also append an html to the table like,
- var tr_html = “
Hello World
”; - $(‘#table_id > tbody:last’).append(tr_html);
Remove all rows from table,
- $('#myTable').find('tr').remove();
You can also delete a particular row from the table using the id of row.
- $(‘#row_id’).remove();
To get last row of the table,
- $(‘#table_id tr:last’);
Get total rows in table,
Use a selector that will select all the rows and take the length.
- var rowCount = $('#table_id tr').length;
If you use or in your table, you’ll have to use the following syntax or you’ll get a incorrect value:
- var rowCount = $('#myTable >tbody >tr').length;
More than 3 requests, I'll translate this to Chinese.
超过3个请求,我就会把这篇文章翻译成中文。
No comments:
Post a Comment