I have var row=<tr><td>val</td><td>val2</td></tr>
and I tried this:
$("#mainTable tbody").append(row);
but it appends to the end of the table.
Also I tried $("#mainTable tr:first").after().append(row);
But have not got a result yet.
Please, help me to understand.
The insertRow() method creates an empty <tr> element and adds it to a table. The insertRow() method inserts the new row(s) at the specified index in the table. Note: A <tr> element must contain one or more <th> or <td> elements.
To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags.
Try this:
$("#mainTable tr:first").after(row);
http://api.jquery.com/after/
InsertAfter is what you are looking for:
var row='<tr><td>val</td><td>val2</td></tr>'; $(row).insertAfter("#mainTable tr:first");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With