Barrie Reader
Barrie Reader

Reputation: 10713

jQuery finding out what is at a particular X/Y co-ordinate?

Hey, I have the following function:

function getPosition() {
    var cLeft = $('#element').position().left;
    var cTop = $('#element').position().top;
}

I also have this:

$('ul#container>li.node:eq('+XXX+')').css({'border' : '5px solid yellow'});

Now, is it possible to determine what index for the LI's is at the co-ordinates provided by getPosition() ?

Note: XXX denotes where I would like the index of the LI's to be.

Upvotes: 1

Views: 46

Answers (1)

alex
alex

Reputation: 490263

Here is some plain JavaScript

var elementAtCoords = document.elementFromPoint(x, y);

I'm not sure support for IE, but Firefox has had it since 3.

To start going crazy with jQuery, simply wrap it

$(elementAtCoords).slideDown(2000);

Upvotes: 1

Related Questions