Skip to content

Instantly share code, notes, and snippets.

@kensnyder
Created February 6, 2013 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kensnyder/4724549 to your computer and use it in GitHub Desktop.
Save kensnyder/4724549 to your computer and use it in GitHub Desktop.
Find all repeated ids in a document
var ids = {};
var repeats = [];
document.body.innerHTML.replace(/ id="(.+?)"/g, function($0, $1) {
if (ids[$1]) repeats.push($1);
ids[$1] = true;
});
console.log(repeats);
// output
["carouselitem-2887", "carouselitem-2850", "slider-2887", "slider-2850", "carouselitem-2887", "carouselitem-2850", "carouselitem-2843", "slider-2887", "slider-2850", "slider-2843", "carouselitem-2887", "carouselitem-2850", "carouselitem-2843", "slider-2887", "slider-2850", "slider-2843", "carouselitem-2918", "carouselitem-2924", "carouselitem-2923", "carouselitem-2922", "carouselitem-2919", "carouselitem-2917", "carouselitem-2916", "carouselitem-2913", "carouselitem-2912", "carouselitem-2911", "carouselitem-2909", "carouselitem-2898", "carouselitem-2897", "carouselitem-2896", "carouselitem-2895", "carouselitem-2892", "carouselitem-2887", "carouselitem-2882", "carouselitem-2881", "carouselitem-2874", "slider-2918", "slider-2924", "slider-2923", "slider-2922", "slider-2919", "slider-2917", "slider-2916", "slider-2913", "slider-2912", "slider-2911", "slider-2909", "slider-2898", "slider-2897", "slider-2896", "slider-2895", "slider-2892", "slider-2887", "slider-2882", "slider-2881", "slider-2874"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment