Question: I have a table in an html form containing a table that a row is added to every time a button is clicked. When each row is added, I want the name and id of each field in the new row (there are four) to be updated from "Id.0" in the first row to "Id.1" in the second row and then "Id.2" in the third, etc. I can accomplish this with the id no problem using

```
var next=$("#QualificationRequirements tr:last").clone();

fixIds(next,nexdex);

nexdex++;

$("#QualificationRequirements").append(next);

function fixIds(element, counter) {
    $(element).find("[id]").add(element).each(function() {
        this.id = this.id.replace(/\d+$/, "")+counter;
    }

}

```

However I have found that the same logic does not apply to the name attribute, and

```
$(element).find("[name]").add(element).each(function() {
    this.name = this.name.replace(/\d+$/, "")+counter;
});

```

causes an error that says I can't call "replace" on a null object, so it appears the name attribute is not being found.

Can anyone see what I'm doing wrong? Thanks!

Answer: 
The issue comes from this part of your statement: `add(element)`

See, `element` refers to the complete row, and rows don't have a name attribute. You just want to act upon the inputs inside the row that have the name attribute so you should remove that part from your code:

```
$(element).find("[name]").each(function() {
    this.name = this.name.replace(/\d+$/, "")+counter;
});

```
use `$(this).attr('name');` to get and set the name attribute.

The full line:

```
$(this).attr('name',$( this).attr('name').replace(/\d+$/, "")+counter);

```