javascript打印dom树

复制粘贴下面的代码到控制台:

function render(node, splits) {
		
		splits.tag += '|----';
		console.log(splits.tag + node.tagName);

		var children = node.children;
		if (!children) return;
		for (var i = 0, len = children.length; i < len; i++) {
			var child = children[i];
			var _tag = splits.tag;
			render(child, splits);
			splits.tag = _tag;
		}
}
var splits = {tag:''}
var start = (new Date()).getTime();
render(document.body, splits);
var end = (new Date()).getTime();
console.log('Cost: ' + (end - start) + 'ms');

 
  

javascript打印dom树_第1张图片


出处: http://blog.csdn.net/nancle/article/details/43054477


你可能感兴趣的:(javascript)