使用纯javascript获取body标签中的所有元素 [英] Get all elements in the body tag using pure javascript

查看:1712
本文介绍了使用纯javascript获取body标签中的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用纯javascript来获取数组中HTML页面的Body标签内的所有元素(标签)。我的意思是没有使用任何框架(例如JQuery)。



我发现你可以使用 document.all 但是会返回整个文档中的所有元素包括脚本。



有没有反正我可以得到这些标签?

谢谢

getElementsByTagName()使用通配符:

  var elems = document.body.getElementsByTagName(*); 


I'm trying to get all the elements (tags) inside the Body tag of an HTML page in an array using pure javascript. I mean without using any framework (ex. JQuery).

I've found that you can use document.all but that will return all the elements inside the whole document including the scripts.

Is there anyway I can get those tags?

thanks

解决方案

If you want all elements inside the body tag, not just first level children, you can simply use getElementsByTagName() with a wildcard:

var elems = document.body.getElementsByTagName("*");

这篇关于使用纯javascript获取body标签中的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆