Reputation: 408
I've some fields that use an array as name like this :
<select name="attr[address][#ID]">
<textarea name="address[#ID][cp]" placeholder="CP"></textarea>
I would like to change the therm "#ID" of all the fields with an unqiue ID using jQuery, is it possible to use something like regex with the .attr() function in order to change the #ID ?
Regards, Adrien
Upvotes: 0
Views: 885
Reputation: 707228
You can replace all occurrences of #ID
in a name attribute with a monotomically increasing number like this:
var cntr = 1;
$("[name*='#ID']").each(function() {
this.name = this.name.replace(/#ID/, cntr++);
});
Upvotes: 5