I have some dynamic generated tables with these html structures
<table class="deliver">
<tbody class="tbody">
<tr id="10" data-position="10">
<td>Title</td>
</tr>
<tr id="10" data-position="10">
<td>Content</td>
</tr>
<tr id="23" data-position="23">
<td>Title</td>
</tr>
<tr id="23" data-position="23">
<td>Content</td>
</tr>
</tbody>
</table>
<table class="deliver">
<tbody class="tbody">
<tr id="3" data-position="3">
<td>Title</td>
</tr>
<tr id="3" data-position="3">
<td>Content</td>
</tr>
<tr id="2" data-position="2">
<td>Title</td>
</tr>
<tr id="2" data-position="2">
<td>Content</td>
</tr>
<tr id="2" data-position="2">
<td>Extra content (sometimes)</td>
</tr>
</tbody>
</table>
Each table has a tbody and tr's. The id and data-position range is between 1 and 23. I need some kind of sorting method which keeps the title-content pairs but sort the id's ascending in each table. I found this and this tutorial, but not worked in my case (nothing happens).
My code snippet looks like this
$(".tbody").each(function(){
$(this).html($(this).children('tr').sort(function(a, b){
return ($(b).data('position')) < ($(a).data('position')) ? 1 : -1;
}));
});