Dean Elliott
Dean Elliott

Reputation: 729

If parent element has certain class, fade in child element

I'm having some trouble with this.

Basically I want to first check if a certain element has a particular class (In this case .active) and, if it does, I want to use jQuery's fadeIn on the .active elements children.

This is what I'm using currently but it doesn't seem to work;

if ( $('.slides li').hasClass('active') ){
    $('.slides li .content').delay(1000).fadeIn('slow');
}

Does anyone have any ideas?

Upvotes: 0

Views: 479

Answers (2)

Krish R
Krish R

Reputation: 22711

Can you try this,

$('.slides li').each(function(){
      if($(this).hasClass('active')){
            $(this).delay(1000).fadeIn('slow');
      }
});

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388316

You can use

$('.slides li.active .content').delay(1000).fadeIn('slow');

in your case any of the li has the class active all .content element within the slides are shown

Upvotes: 1

Related Questions