I'm simulating the process of clicking all buttons in a page and now I would like to have some delay between each click by using the following code, but for some reason it refuses to work and no button is clicked:
var time = 500;
$("button").each(function() {
setTimeout(function() {
$(this).click();
}, time);
time += 500;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<title>TEST</title>
</head>
<body>
<button type="button">Click Me!</button>
<button type="button">Click Me!</button>
<button type="button">Click Me!</button>
<button type="button">Click Me!</button>
<button type="button">Click Me!</button>
<button type="button">Click Me!</button>
<button type="button">Click Me!</button>
</body>
</html>
Any ideas?