Skip to content

Instantly share code, notes, and snippets.

@diverted247
Created September 9, 2013 13:14
Show Gist options
  • Save diverted247/6495409 to your computer and use it in GitHub Desktop.
Save diverted247/6495409 to your computer and use it in GitHub Desktop.
TypeScript compatible live browser test for duplicate element ids via http://stackoverflow.com/questions/482763/jquery-to-check-for-duplicate-ids-in-a-dom
export function dupTest() {
var elms = document.getElementsByTagName( "*" ), i, len, ids = {}, id;
for( i = 0, len = elms.length; i < len; i += 1 ){
id = elms[ i ][ 'id' ] || null;
if( id ){
ids[ id ] = ids.hasOwnProperty( id ) ? ids[ id ] +=1 : 0;
}
}
for( id in ids ){
if( ids.hasOwnProperty( id ) ){
if( ids[ id ] ){
console.warn( "Duplicate ID #" + id );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment