how to click multiple buttons in a row with javascript?
how to click multiple buttons in a row with javascript?
is it possible to create script that click multiple buttons in a row with x time interval between clicks ?
for example when first button is clicked after x time second is clicked and etc.
(using Javascript).
var inputs = document.getElementsByClassName('className');
for(var i=0; i<inputs.length;i++)
setInterval(function()
inputs[i].click() ,1000
Sure it's most likely possible. Show us what you have tried and where you ran into problems
– charlietfl
Sep 1 at 13:25
2 Answers
2
use this code
var allButtons = document.getElementsByClassName("button")
var timeInterval = 5000 // x time in miliseconds
function pressButton(iteration=0)
setTimeout(function()
allButtons[iteration].click();
pressButton(iteration++);
, timeInterval)
pressButton();
<div id="parent">
<button class="button" type="submit" > </button>
<button class="button" type="submit" > </button>
<button class="button" type="submit" > </button>
<button class="button" type="submit" > </button>
<button class="button" type="submit" > </button>
</div>
More can be helped if you paste your code
<div>
<button id="button1" onClick="alert('click button1');">Button 1</button>
<button id="button2" onClick="alert('click button2');">Button 2</button>
<button id="button3" onClick="alert('click button3');">Button 3</button>
</div>
<script>
var clickcallback = function(i)
setTimeout(function()
let id = "button" + i;
document.getElementById(id).click();
, 1000); // one second
if(i <= 3)
clickcallback(i+1);
;
clickcallback(1);
</script>
Here the demo:
https://jsfiddle.net/frasim/730xmhfv/8/
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Please post the codes that you've tried.
– Chaska
Sep 1 at 13:23