I’ve got a form on a website with a bunch of input elements. The name attribute for these elements is of the form “property-0”. However, the user may need multiple fieldsets just like the current one, so I clone the fieldset with jQuery clone(), but then I need to increment the number on the end. The number could be above 10, so I can’t just select the last character.
This is what I am trying:
name.replace(/([0-9]+)$/, String(Number('$1')+1));
but it just gives me property-NaN. Anyone know what I’m doing wrong?
You can pass a function in as the second argument to
.replace(), like this:You can test it out here, feel free to replace
+mwithparseInt(m, 10)if you’re mor comfortable with that.