agon024 agon024 - 3 months ago 23
CSS Question

jQuery - Exclude elements from object loop

So I am using this code to loop through the DOM and locate all elements that match and then add a class to the elements:

var timeDif = 0;

setTimeout(function(){

$('.panel-main').each(function () {
var $el = $(this);
setTimeout(function () {
$el.addClass('boingInUp');
},200 * timeDif);
timeDif++;
});

}, 1000);


what I need to know how to do is exclude any elements that have an inline style of " style="display: none; ". Is this possible?

Thank you in advance.

Answer

Depending on your complete use case, you should use the jQuery visibility selector.

$('.panel-main:visible').each(function() {
  ...
}

This continues to work for elements that have that inline style, regardless if you show them or not.

Documentation

Comments