I was trying to clone and change all the ids of a line in a table following the answer https://stackoverflow.com/a/2977114/327247 but the code below doesn't change the first id: the row id. The javascript is
var $clone = $("#RowPly-R1-P1");
$clone.find('[id]').each(function() {
var $th = $(this);
var newID = $th.attr('id').replace(/-P\d+$/,
function(str) { return "-P"+i; });
console.log(newID);
$th.attr('id', newID);
});
console.log($clone);
$clone.appendTo($tableToModfiy);
$clone.after($("RowPly-R1-P1"));
while the html is
<tbody id="tblPlayers">
<tr id="RowPly-R1-P1">
<td>1</td>
<td>
<div class="input-group">
............
</div>
</td>
</tr>
</tbody>
All the ids internal to the row are successfully changed.I cannot understand why find doesnt change the first ID.