admin管理员组文章数量:1317906
I have a collection of elements on my page, and I want to see if they are visible or not currently.
So:
$(".someClass")
How can I loop through and figure this out? because if it is visible, i have to fire another function.
I have a collection of elements on my page, and I want to see if they are visible or not currently.
So:
$(".someClass")
How can I loop through and figure this out? because if it is visible, i have to fire another function.
Share Improve this question asked Apr 16, 2009 at 19:48 BlankmanBlankman 267k332 gold badges795 silver badges1.2k bronze badges 04 Answers
Reset to default 9$(".someClass").each(function(){
if($(this).is(":visible")){
//item is visible: do something
}
});
how about that?
$(".someClass:visible")
will return the visible ones.
What you could do:
$(".someClass").each(function(x) { if ( x.style.display != "none" && x.style.visibility != "hidden" ) { your_function(); } });
where your_function()
is the name of your function.
All solutions in terms of $('.someClass').is(':visible')
are unreliable. All it tells us is if a particular element has a styling of display:none
or visibility:hidden
. This is not the same as whether an element is visible!
Consider a situation like this:
<div style="display:none;"><div class="someClass"></div></div>
Everybody can see that the element designated by $('.someClass')
is invisible. But $('.someClass').is(':visible')
will return true
!
The only water-proof solution is to not only check for is(':visible')
on the $('.someClass')
, but on all of its parent elements as well. Only if for none of the parents holds that is(':visible') === false
, we can conclude that $('.someClass')
is actually visible.
本文标签:
版权声明:本文标题:javascript - Determine if collection of elements are visible using JQuery like $(".someClass") - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742031773a2416577.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论