Please explain how you can hang a class on each element of the array at a certain interval?
$(function() { $array = $('.array-item'); setTimeout(function() { $array.each(function() { setTimeout(function() { $(this).addClass('red'); }, 300); }); }, 1000); }); div { display: block; width: 100px; height: 50px; padding: 15px; background-color: green; font-size: 20px; line-height: 20px; text-align: center; } div.red { background-color: red; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="array-item">1</div> <div class="array-item">2</div> <div class="array-item">3</div> then I want a second after the page loads, the green blocks turn red in turns with an interval of 300ms. If possible, I would like to see a solution on both JS and JQ. Thank you in advance))
PS and please indicate why my code does not work)))