如何使用jQuery测试某个元素是否隐藏?

55

可能重复:
如何使用 jQuery 测试元素是否隐藏

在 jQuery 中,假设您有一个通过使用 .hide().show().toggle() 隐藏和显示的某种元素。如何测试该元素当前是否在屏幕上隐藏或可见?

2个回答

44

请尝试

$("some-selector").is(':hidden');

或者

$("some-selector").is(':visible');  

这里是 :visible:hidden 选择器的文档。


9
$('.target').is(':hidden') // returns true if the element is hidden
$('.target').is(':visible') // returns true if the element is visible

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接