title: jQuery: Finding duplicate ID's and removing all but the first
body: <pre><code>    $('[id]').each(function () {
  
          var ids = $('[id="' + this.id + '"]');
  
          // remove duplicate IDs
          if (ids.length &gt; 1 &amp;&amp; ids[0] == this) $('#' + this.id).remove();
  
      });
  </code></pre>
  
  <p>The above will remove the first duplicate ID, however I want to remove the last. I've tried <code>$('#'+ this.id + ':last')</code> but to no avail.</p>
  
  <p><a href="http://jsfiddle.net/z4VYw/1/" rel="noreferrer">Fiddle</a></p>
  
  <p>In the fiddle the input with the value 'sample' should be kept when the append action takes place.</p>