IneedYOURhelp
IneedYOURhelp

Reputation: 17

How can I click button every 1 seconds?

I have button declarated:

<button type="button" class="btn btn-warning" style="top: -1px; position: relative; margin-left: 10px;" onclick="searchProduct()">Refresh / Search</button>

What I should write in console to click that button every 1 seconds? I found that code, but I don't know how to use it:

setInterval(function () {document.getElementById("myButtonId").click();}, 1000);

Upvotes: 0

Views: 559

Answers (2)

Damien
Damien

Reputation: 1600

You need to add the id "myButtonId" to your html code.

setInterval(function () {
document.getElementById("myButtonId").click();
console.log('click');
}, 1000);
<button type="button" class="btn btn-warning" id="myButtonId" style="top: -1px; position: relative; margin-left: 10px;">
Refresh / Search
</button>

Upvotes: 0

wkb
wkb

Reputation: 56

The button executes the searchProduct() function, so you can directly execute it. No need to click the button

setInterval(function() {
  searchProduct();
}, 1000);

Upvotes: 3

Related Questions