Skip to content

Instantly share code, notes, and snippets.

@livingston
Created April 24, 2010 20:41
Show Gist options
  • Save livingston/377931 to your computer and use it in GitHub Desktop.
Save livingston/377931 to your computer and use it in GitHub Desktop.
Get all unique tags in a page
/* Get List of Unique Tags used in the page
* @author: Livingston Samuel
*/
var uniqueTags = (function (win, doc) {
var allElems = doc.getElementsByTagName('*'),
len = allElems.length, elem, tags = {}, arr = [];
while(len--) {
elemName = allElems[len].nodeName;
if(!tags.hasOwnProperty(elemName)) {
tags[elemName] = true;
arr.push(elemName);
}
}
delete tags;
delete allElems;
return (arr.sort().join(', ').toLowerCase());
}(window, document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment