jQuery-如何检查隐藏的DIV中的子对象是否可见? [英] Jquery - How to check, if child in hidden DIV is visible?

查看:76
本文介绍了jQuery-如何检查隐藏的DIV中的子对象是否可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看隐藏的div中的div ...是否可见?

how can i check a div in a hidden div ... if visible or not?

HTML

<div style="display:none;">
  <div id="two_child"></div>
  <div id="three_child" style="display:none"></div>
</div>

JS

if($('#two_child').is(':visible'))
{
  alert('true');
}

这将不起作用.

有什么想法吗?

提前谢谢! 彼得

推荐答案

您可以检查CSS的display属性:

You could check the display property of the css:

if ($("#two_child").css("display") != "none") {
    //...
}

正如Gaby在评论中指出的那样,如果使用visibility隐藏您的元素,这将不起作用,因此您可能希望将其扩展为:

As Gaby points out in the comments, this would not work if your elements are being hidden using visibility, so you may want to extend it to:

var $child = $("#two_child");
if ($child.css("display") != "none" && $child.css("visibility") != "hidden") {
    //...
}

这篇关于jQuery-如何检查隐藏的DIV中的子对象是否可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆