Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  120] [ 6]  / answers: 1 / hits: 56426  / 11 Years ago, fri, september 13, 2013, 12:00:00

I cant seem to click all of the elements.


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

This works but will only click on the first element. I need this to click all of the elements with class 'node closed'.


Thanks


More From » class

 Answers
47

[0] means only the first element of the node list returned by 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();
}


Working Demo


[#75709] Thursday, September 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;