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





Please post the codes that you've tried.
– Chaska
Sep 1 at 13:23





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)