$(newRow).find('[id*="rules"]').each(function(){ // Update the 'rules[0]' part of the name attribute to contain the latest count $(this).attr('name',$(this).attr('name').replace('rules[0]','rules[$count]')); });