Choosing jQuery by position on page?

Is there a selector in jQuery to select elements that have a specific page position, for example, all elements that have an offsetTop greater than, say, 100px?

I tried:

$('span[offsetTop>100]') 

since we can check whether the attribute matches a certain value, I thought that we can check if the attribute exceeds a certain value. This, however, does not work. Is this even possible?

+4
source share
1 answer

You will need to use the filter() (docs) method to filter() <span> elements by their offset:

 $('span').filter(function() { return $(this).offset().top > 100; }); 
+9
source

Source: https://habr.com/ru/post/1338909/


All Articles