This is my text input box
<input class="tb" id="tb43[0]" type="text" size="30" maxlength="200" />
When cloning with jQuery I’d like the id of the new cloned box to be “tb43[1]”.
$clone.find(".tb").attr("id").replace(/\d+/, function (val) { return parseInt(val) + 1; });
This only increments the first number but how can I manage to increment the number in the square brackets?
Thanks
.attr("id", function() {})to change the ID. You’re currently not altering the ID.+instead ofparseInt(the latter has some caveats).E.g.