Jquery查找 - 仅可见

new*_*bie 6 jquery

我想检查div是否包含类"错误"的子项,但条件是错误类显示不等于none.(含义错误类必须是可见的.

如何更改我的代码如下:

 $(".related_field").each(function(){
     var $widthAdj = $(this).find(".autoDiv");
     if($(this).find(".error").length == 0){  //MUST BE VISIBLE "ERROR" CLASS ONLY
        $widthAdj.css("height","48px");
     } else {
        $widthAdj.css("height","63px");
     }
 });
Run Code Online (Sandbox Code Playgroud)

mat*_*mmo 9

你的意思是这样的?使用:visible选择器:

if($(this).find(".error:visible").length == 0)
    $widthAdj.css("height","48px");
} else {
    $widthAdj.css("height","63px");
}
Run Code Online (Sandbox Code Playgroud)