I have an area on my website that I allow users to update their profile information.
html
<div class="my-class">
<input type="text" name="fields[myFieldHandle][1][fields][firstName]" value="">
<button type="button" id="add">Add Another</button>
</div>
jquery
$('#add').click(function (event) {
$('.my-class').clone().insertAfter('div.my-class');
});
All is well, I am able to clone the text input. However, I need to be able to increment the [1] value by one. I could try matching the string, but I feel that is assuming quite a bit. Is there a more effective way to clone this:
<input type="text" name="fields[myFieldHandle][1][fields][firstName]" value="">
to this:
<input type="text" name="fields[myFieldHandle][2][fields][firstName]" value="">