SO - 19583788
HTML
<input type="text" id="test1" />
<br/>
<input type="text" id="test1" />
<br/>
<input type="text" id="test2" />
<br/>
<input type="text" id="test3" />
<br/>
<input type="text" id="test3" />
<br/>
<input type="text" id="test4" />
<br/>
JavaScript
// Get all the items with Duplicate id
var $itemsThatHasIdDuplicate = $('[id]').filter(function () {
return $('[id="' + this.id + '"]').length > 1;
});
// Modify the id for all of them
$itemsThatHasIdDuplicate.attr('id', function (i, val) {
return 'newID' + (i + 1);
});