1

The :visible jQuery selector says that it will select all the elements which consumes space. Is there any other selector that will get the visible elements on the viewport ?

James Donnelly
  • 126,410
  • 34
  • 208
  • 218
Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135
  • What's your aversion to using `:visible`? – James Donnelly May 08 '15 at 17:17
  • 3
    @JamesDonnelly - I think the OP wants only visible elements that are in the viewport, where `:visible` will select any element with a width and height. – j08691 May 08 '15 at 17:19
  • 2
    The doc also states that "Elements with visibiliy:hidden" are considered visible, since they still consume space in the layout. But i want to get only the elements that are "visible and currently on viewport" not just visible. – Talespin_Kit May 08 '15 at 17:19
  • @j08691 ah. must have overlooked that bit at the end! – James Donnelly May 08 '15 at 17:20
  • Loop through the results of :visible and filter out the ones with visibility hidden and opacity zero as well as above the scroll? – Radio May 08 '15 at 17:22
  • That is not very efficent, Since in my case the document contains more than 1000 elements (special use case) and it is not very efficent to loop through every time. This one is really awesome http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport/7557433#7557433 – Talespin_Kit May 08 '15 at 17:26
  • http://stackoverflow.com/questions/16782925/using-jquery-how-do-you-find-only-visible-elements-and-leave-hidden-elements-al – Red2678 May 08 '15 at 17:29
  • 1
    for what it's worth I think this is a great question, and I don't agree that the referred answer has the solution to this problem. This question is about requesting all visible elements in the viewport. The other question is about checking whether a given element is inside the viewport or not. – Jules Colle Dec 03 '20 at 00:41

0 Answers0