$(\'[id]\').each(function () { var ids = $(\'[id=\"\' + this.id + \'\"]\'); // remove duplicate IDs if (ids.length > 1 && id
Try:
$('[id="' + this.id + '"]:not(#" + this.id + ":first)').remove();