开发者

jQuery fade parent if child nodes are styled display:none

I have divs with class "someclass"; each div 开发者_开发知识库has child divs with class "otherclass".

I need to check if the divs with "otherclass" are display:none and then fadeout the parent with "someclass"

How can I do it every time I click on some checkbox on the page?


$(':checkbox').click(function(){

  if( $('.otherclass').css('display')=='none' ){

    $('.otherclass').parent().fadeOut('normal');

  }

}

This is assuming .otherclass is a unique identifier. Also, if you want to to link these elements to the checkbox that is clicked with, say, the same class it's a little more involved.

$(':checkbox').click(function(){

  var el = $(this).attr('class'); //Better to use a unique ID here

  if( $('div.' + el).css('display')=='none' ){

    $('div.' + el).parent().fadeOut('normal');

  }

}


$(":checkbox").click(function() {
    if(!$(".otherclass:visible").length)
        $(".someclass").fadeOut();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜