Last active
August 29, 2015 14:10
-
-
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
This file contains hidden or 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
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