How to slow jquery click function execution?

I am using a simple jquery command in the Google Chrome console to manage my site. Basically, I have to approve a few new requests every day, so I use:

$('.approve').click();

where 'approve' is the class name of the button to click. It saves me hours. However, this resets my browser every time, and sometimes it doesn’t work, mainly due to the fact that it is taxed on my laptop. I was looking for a way to slow down the function. I tried...

$('.approve').click().delay(1000);

to try to slow it down for 1 second between button presses. This does not seem to work (it happened without errors, but I don't think it slowed down the click.

Any ideas?

Edit:

Someone pointed out that this could be a duplicate of another question. The reason for this is not because the other main answer focuses on using JS to define a function that uses setTimeout (), where I am looking for my own jquery method for this. I understand that jquery is written in JS, but since I use it in the command console, I do not have the luxury of a few lines of space for coding.

Can someone tell me why the above function will not work? It seems like it should be based on my research.

Thanks in advance.

+4
source share
4 answers

Wait 1 second between each press of a button:

.approve, click : (setTimeout)

$('.approve').each(function(index) {
    var $approve = $(this);
    setTimeout(function() {
        // Simulation click event
        $approve.trigger('click'); 
    // 0, 1, 2, 3, ... times 1000 to bring delay to miliseconds
    }, index * 1000); 
});

( IE9 +):

$(".approve").each(function(c){setTimeout(function(c){c.click()},1e3*c,$(this))});

:

$(".approve").each(function(e){var i=$(this);setTimeout(function(){i.click()},1e3*e)});
+2

, :

$(".approve").click(function(){
    setTimeout(function(){
        // Do something
    }, 1000);
});
0

If you want to output your function once, use setTimeout()

$(".approve").click(function(){
    setTimeout(function(){
    }, 1000);
});

If you want to output it every second, use setInterval()

0
source

when you click to run a function that will execute the setTimeout function

$('.approve').click(function(){
  setTimeout(function(){
  // here some code u want to execute after 5 sec //
  }, 5000);
});
0
source

Source: https://habr.com/ru/post/1609346/


All Articles