D
D
Disrespector2020-05-09 17:13:55
JavaScript
Disrespector, 2020-05-09 17:13:55

How to click on all elements of the same class?

The site displays elements, among which there are elements with the class " 5eb6ba34b659c646819005.png", how to click on all elements with this class at once? When executing this code, the click goes through only one element. If you execute this code several times through the browser console, then it will click on these elements in order.

var btn = document.getElementsByClassName('itemclass');
for(var i = 0; i < btn.length; i++)
btn[i].click();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
be_a_man, 2020-05-09
@Disrespector

So

D
Dubolom Unicellular, 2020-05-09
@duboloms

Why cycle??????

var btn = document.getElementsByClassName("itemClass");
btn.click();

By default, all selectors are selected.
By the way, get acquainted with ES6 if you are sick of these getElement (-s) and much more introduced
Also the second part of the article: https://tproger.ru/translations/es6-cheatsheet-2/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question