There is:
setInterval ( function() { document.getElementsByClassName('farm_icon_a').click(); }, 1000 ); I receive:
Uncaught TypeError: document.getElementsByClassName (...). Click is not a function at: 3: 56
How to do?
There is:
setInterval ( function() { document.getElementsByClassName('farm_icon_a').click(); }, 1000 ); I receive:
Uncaught TypeError: document.getElementsByClassName (...). Click is not a function at: 3: 56
How to do?
It is better to use querySelector instead of getElementsByClassName , because it caches the result.
getElementsByClassName returns a nodeList, which is a pseudo-array that does not have ordinary array methods.
You need to convert nodeList to an array through Array.prototype.slice.call(nodeList) or Array.from() (this is a new method and not all browsers are supported), go through this array by loop and make click() on each element
var buttons = Array.prototype.slice.call(document.querySelectorAll('.farm_icon_a')); buttons.forEach(function(button, index) { setTimeout(function() { button.click(); }, index * 100); }); buttons.forEach((button,index) => { setTimeout(() => { button.click(); }, 100 * index); }); Then every trace. the element will be launched with a delay of + 100 ms. And how to run the code again is up to you. You can use setInterval, or you can click. - DimenSi setInterval ( function() { var arr = document.getElementsByClassName('farm_icon_a'); for(var i = 0; i < arr.length; i++) { arr[i].click(); } }, 1000 ); // get button array (Из соседнего ответа) var buttons = Array.prototype.slice.call(document.querySelectorAll('.farm_icon_a')); var clickers = buttons.map(function(button) { return function(){ button.click(); } }); var index = 0; setInterval(function(){ if (index == clickers.length) index = 0; clickers[index](); index++; }, 500); Source: https://ru.stackoverflow.com/questions/621185/
All Articles
document.getElementsByClassName('farm_icon_a')gives you an array of all the elements, scrolls through the array and makes a click on each of them. - Moonvvellif (item.click) item.click(); - nick_n_a