如果我有以下 HTML:
<div style="display:none;">
<span id="hello">Hey</span>
</div>
我做 alert($("#hello").css("display"));
,它会说“内联”。跨度显然不可见,但由于它没有直接具有 display:none;
属性,它仍然说它是可见的。
如何测试某个 DOM 元素是否实际上可见,即使其父元素或其父元素的父元素未显示?
最佳答案
您可以使用:
if ($('#myitem').is(':visible')){
/*Do some sort of stuff in here */
}
仍在动画中的项目(如使用 .hide
或 .fadeOut
)将“可见”直到动画完成
关于javascript - 使用 jQuery 检查 DOM 元素的继承可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11267335/