可以像在JQuery中一样选择JavaScript中的多个元素吗?

时间:2015-03-24 08:56:39

标签: javascript multipleselection

情况是这样的:我有一个函数接受一个类的名称,就像在JQuery中一样:select(" .item");我使用的功能内部 document.getElementsByClassName() 但是,如果我使用select(" .item,.prize"),则它不起作用,因为您无法使用documents.getElementsByClassName()来选择多个类。有没有办法只使用JavaScript选择多个元素?

1 个答案:

答案 0 :(得分:0)

我相信document.querySelectorAll正是您所寻找的:

document.querySelectorAll(".item, .prize")

这应该返回一个包含类itemprize的所有元素的列表。