Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select elements within boundary?

I'm trying to figure out a way to select elements that are overlapped (and contained, completely covered up) within an absolutely positioned div.

I basically need to select elements within a certain pixel boundary. How can this be done using jQuery?

like image 515
Andrew Avatar asked Jul 21 '26 17:07

Andrew


1 Answers

Here's the basic idea:

var left = 100,
    top = 200,
    right = 300,
    bottom = 500;

$('#main-div').children().filter(){
    var $this = $(this),
        offset = $this.offset(),
        rightEdge = $this.width() + offset.left,
        bottomEdge = $this.height() + offset.top;

    if (offset.top > top && offset.left > left && right > rightEdge && bottom > bottomEdge) {
        return true;
    }

    return false;
});

Change the coordinates at the top to whatever you need.

like image 149
Joseph Silber Avatar answered Jul 23 '26 06:07

Joseph Silber