0

It's my code. This click goes on indefinitely. I would like to stop him after the first time.

<input type="button" name="submitbre" id="loadBtn" value="Load More">

<script>
var btn = document.querySelector("[name='submitbre']");
setInterval(function(){
btn.click();
},4000);
</script>
marko
  • 3
  • 2

1 Answers1

0

You need to use setTimeout instead of setInterval. setTimeout will run the function just once, while setInterval runs the function periodically.

More info: https://javascript.info/settimeout-setinterval#:~:text=setTimeout%20allows%20us%20to%20run,repeating%20continuously%20at%20that%20interval.

viniciusjssouza
  • 1,235
  • 14
  • 28