Created
September 9, 2013 13:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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