Skip to content

Instantly share code, notes, and snippets.

@ohnishiakira
Created June 10, 2011 19:54
Show Gist options
  • Save ohnishiakira/1019637 to your computer and use it in GitHub Desktop.
Save ohnishiakira/1019637 to your computer and use it in GitHub Desktop.
/*
* http://www.w3.org/TR/ElementTraversal/ にある
* - firstElementChild
* - nextElementSibling
* - childElementCount
* を使ったサンプル
*/
function traverseTree(element, indent) {
var tagName = element.tagName;
var child = element.firstElementChild;
var childCount = element.childElementCount;
console.log(indent + tagName);
while (child) {
traverseTree(child, indent + " ");
child = child.nextElementSibling;
}
}
var time = 0;
time = new Date();
traverseTree(document.body, "");
time = new Date() - time;
console.log("total time: " + time);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment