I want to add a row to a table and then use it as a DOM object. Assume the following HTML:
<table> <tr class="existing-row"><td> <a>add new row</a> </td></tr> <tr class="existing-row"><td> <a>add new row</a> </td></tr> </table>
I am using the following JavaScript with jQuery to insert a string:
function addNewRow(addNewRowLink) { var currentRow = addNewRowLink.closest('tr'); currentRow.after('<tr class="added-row"><td>This is new</td></tr>'); var newRowInDomTree = currentRow.next('tr');
The variable newRowInDomTree contains tr.existing-row instead of a tr.added-row . It seems that the DOM tree is not updating, but I do not understand why.
Any ideas?
Thanks for the advanced.
source share