Skip to content

Instantly share code, notes, and snippets.

@ssp
Last active August 29, 2015 14:10
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 ssp/c09055a5e9df8fb5a30c to your computer and use it in GitHub Desktop.
Save ssp/c09055a5e9df8fb5a30c to your computer and use it in GitHub Desktop.
Iterates the DOM and logs tag names, classes and id to the console
iterate = function (e, level) {
var message = '';
e.children().each( function() {
var logString = '';
for (var i = 0; i < level; i++) { logString += '>'; }
logString += this.nodeName + ' ';
if (this.id) { logString+= '#' + this.id + ' '; }
if (typeof this.className === 'string') { logString += '.' + this.className.split(' ').join(' .'); }
message += logString + "\n";
message += iterate($(this), level + 1);
} );
return message
}
iterateAll = function () {
console.log(iterate($('body'), 0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment