Reputation: 17
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
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
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