[jQuery] Destroying parent tag when restoring original value.

[jQuery] Destroying parent tag when restoring original value.


Having a heck of a time figuring this out, I have made a few fields
(<td>'s>editable, so when you click on them it puts in a form with a
text box and a button to submit, and a button to undo it.
Well when I undo it, everything looks fine but the data is trapped in
another set of <td> tags. Is their anyway to kill off these extra
<td>'s, because this can keep happening every time someone clicks on
it and undoes it.
Code:
function setClickableTitle(obj, i) {
    $(obj).click(function() {
     var account = $(obj).attr('accountno');
     var id = $(obj).attr('id');
     var title = $(obj).attr('title');
     var revert = $(obj).html();
     var test = "code that goes into the <td> just clicked";
$(obj).after(test).remove();
$('.titleClose').click(function(){stepBackTitle(this, revert, i,
id, title, account);});
});
function stepBackTitle(obj, revert, n, id, title, account) {
    $(obj).parent().replaceWith("<td id='" + id + "' title='" + title +
"' accountno='" + account + "'>" + revert + "</td>");
    setClickableTitle($("td[title]").get(n), n);
    };
    }