用getElementsByClassName选择所有类并单击 [英] Select all class's with getElementsByClassName and click

查看:564
本文介绍了用getElementsByClassName选择所有类并单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法点击该类的所有内容。

I cant seem to click all of the class's

document.getElementsByClassName('node closed')[0].click();

这可以工作,但只会点击第一个类,我需要点击所有名为'node closed'

This works but will only click on the first class, I need this to click all of the classes named 'node closed'

谢谢

Thanks

推荐答案

[0] 表示仅由 getElementsByClassName 返回的节点列表的第一个元素。

[0] means only the first element of the node list returned by getElementsByClassName.

您必须执行 getElementsByClassName 并遍历所有匹配元素,如下所示:

You have to do getElementsByClassName and iterate through all the matched elements like shown below:

var el = document.getElementsByClassName('node closed');
for (var i=0;i<el.length; i++) {
    el[i].click();
}

工作演示

这篇关于用getElementsByClassName选择所有类并单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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