JavaScript Check for Duplicate IDs on Page

Using jQuery:

function check_for_duplicate_ids() {
    // iterator over every element on page w/ id attribute set
    $('[id]').each(function(){
        // find all elements on page by id where id is this.id
        var ids = $('[id="'+this.id+'"]');
        if(ids.length>1 && ids[0]==this) {
        // we have more than 1 id and the id is same as
        // element we are iterating over
            console.warn('Multiple IDs #'+this.id);
        }
    });
}