Question about cloning a table row and changing various ids

Question about cloning a table row and changing various ids

I'm new to jquery so I'm having a bit of an issue cloning a table row and having all of the id's change correctly.

I'm able to clone a row with no problem and change the id of the tr after clicking a button by doing this:

var newId = document.getElementById("id").value; // This works because I am using a hidden input for my id
$(id).clone().attr("id", "row" + newId).insertAfter("#div_id");// This changes the id of row

The problem I am having is when I want to change the other id's inside of the tr. After insertAfter() I'll do the following:

.find("span").text("Item" + newId).find("#Item_A" + oldId).attr("id", "Item_A" + newId);

The first .find will change the text with no problem, its when I get to Item_A that it will keep the old id instead of incrementing to the new id. Yes, I am declaring oldId as a variable and assigning it as newId - 1. Any ideas on how to make sure all id's are incremented properly?