I need to update a specific table row (via tr id="unique_key") after a successful AJAX call.
HTML fragment:
<a name=\"p{$product_id}\" class=\"tr{$product_id}\"></a>
<tr id="p{product_id}" class="item-row">
<td><h3>{product_id}</h3><a rel="facebox" href="ajax_url">{product_name}</a></td>
<td>{image_information}</td>
<td>{image_sortiment}</td>
<td>{product_status}</td>
</tr>
Javascript:
// AJAX Call
success: function(msg){
$('#p' + prod_id).remove();
$('.tr' + prod_id).after(msg);
$('#p' + prod_id + ' a[rel*=facebox]').facebox();
}
...
What happens:
<tr>
's) so my 'hook' disappearsWhat's wrong with my idea? How can i force jQuery to 'overwrite' the required table row?
Initially, the table is empty, so the output is shown with “No student record” with an “Edit” button and the “Add new row” button. On adding a new row using JavaScript, the row object is cloned after the last row. Any row can be deleted which is implemented by using jQuery remove() method as shown in the code.
After creating a table in JavaScript, you can insert and combine rows and columns or format the table by adjusting table cell widths, colors, and alignment. You can use the contenteditable attribute on the cells, rows, or table to edit a table.
Update a Row This function uses that ID to locate the button that contains the data- attribute within your table. The code snippet below shows just the changed lines in this updated function. function productUpdateInTable(id) { // Find Product in <table> var row = $("#productTable button[data-id='" + id + "']") .
You can't have anchors inside the table but outside the table rows. All content in a table has to be inside the table cells. If you put content outside the cells, browsers try to fix the code so that it's possible to display it, usually by moving it to after the table.
Manipulating content in a table can be tricky, it can act up if you add rows as html chunks rather than row elements. Use the jQuery function to create elements from the string that you get.
var row = $(msg);
$('#p' + prod_id).replaceWith(row);
You can not have any non-table elements directly inside <table>
but not inside <td>
or <th>
. Browsers won't render it correctly.
So you have to place anchors in another <tr><td> .. </td></tr>
But if they are there only to remove row and create new one, you can try replaceWith() instead:
$('#p' + prod_id).replaceWith(msg);
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