码迷,mamicode.com
首页 > 编程语言 > 详细

javascript打印dom树

时间:2015-01-23 14:44:33      阅读:218      评论:0      收藏:0      [点我收藏+]

标签: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');


技术分享


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


javascript打印dom树

标签:javascript   dom   

原文地址:http://blog.csdn.net/nancle/article/details/43054477

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!