.each .children() element with delay

125 Views Asked by At

I build this scraping out the answers on stackoverflow. What i want to achive:

For each .element in .element-wrapper add the class .visible with delay 1000ms .

$('.element-wrapper').children('.element').each(function(i) {
  var $item = $(this);
  setTimeout(function() {
    $('.element').addClass('visible');
  }, 1000 * i);
});
1

There are 1 best solutions below

2
Praveen Kumar Purushothaman On BEST ANSWER

Actually you are almost right... Just change one line below to make it context sensitive to the current wrapper:

$('.element-wrapper').children('.element').each(function(i) {
  var $item = $(this);
  setTimeout(function() {
    $item.addClass('visible');  // Change this line.
  }, 1000 * i);
});