Skip to content

Instantly share code, notes, and snippets.

@ssp
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save ssp/c09055a5e9df8fb5a30c to your computer and use it in GitHub Desktop.

Select an option

Save ssp/c09055a5e9df8fb5a30c to your computer and use it in GitHub Desktop.

Revisions

  1. ssp revised this gist Nov 26, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion iterate-dom.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ iterate = function (e, level) {
    for (var i = 0; i < level; i++) { logString += '>'; }
    logString += this.nodeName + ' ';
    if (this.id) { logString+= '#' + this.id + ' '; }
    if (this.className) { logString += '.' + this.className.split(' ').join(' .'); }
    if (typeof this.className === 'string') { logString += '.' + this.className.split(' ').join(' .'); }
    message += logString + "\n";
    message += iterate($(this), level + 1);
    } );
  2. ssp created this gist Nov 26, 2014.
    17 changes: 17 additions & 0 deletions iterate-dom.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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 (this.className) { logString += '.' + this.className.split(' ').join(' .'); }
    message += logString + "\n";
    message += iterate($(this), level + 1);
    } );
    return message
    }

    iterateAll = function () {
    console.log(iterate($('body'), 0));
    }