Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector by position on page available?

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

I tried:

$('span[offsetTop>100]')

because just as we can check if an attribute equals to some value, I thought it might be possible to check if an attribute is larger than some value. This, however, does not work. Is this possible at all?

like image 629
pimvdb Avatar asked Jan 20 '23 13:01

pimvdb


1 Answers

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

$('span').filter(function() {
    return $(this).offset().top > 100;
});
like image 170
user113716 Avatar answered Jan 29 '23 09:01

user113716