How to click a button every second using JavaScript?
You use document. getElementById("button-id"). click() to click your button.
If you want it to repeat, just call the function that's set to the click listener of clickButton . Unless you mean over and over, in which case use setInterval or setTimeout (less recommended). I put the code within my page: <head> <script type="text/javascript"> window. onload = function(){ document.
setInterval(function () {document.getElementById("myButtonId").click();}, 1000);
This will give you some control over the clicking, and looks tidy
<script>
var timeOut = 0;
function onClick(but)
{
//code
clearTimeout(timeOut);
timeOut = setTimeout(function (){onClick(but)},1000);
}
</script>
<button onclick="onClick(this)">Start clicking</button>
document.getElementById('youridhere').click()
This would work
setInterval(function(){$("#myButtonId").click();}, 1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With