Glockohnee Glockohnee - 25 days ago 10
jQuery Question

.each .children() element with delay

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);
});

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);
});