fancy
fancy

Reputation: 51333

jQuery index of dom element?

I have...

element = document.elementFromPoint(x, y)

then I want to do something like...

index = $(element).index()

The DOM element is a li and I need its position in the list.

Thanks!

EDIT: If what i'm doing is correct then something here is wrong, Touch events over two dom elements?

Any help is much appreciated.

Upvotes: 1

Views: 1891

Answers (3)

fancy
fancy

Reputation: 51333

This works: index = $(element).index()

Upvotes: 0

FloydThreepwood
FloydThreepwood

Reputation: 1585

$(element) will work, if you want to know its position you need to select it's preceding siblings.

jQuery than gives you the length property, wich works like on arrays.

$(element).prevAll().length;

Upvotes: 3

zzzzBov
zzzzBov

Reputation: 179046

What you want is $('li').index(element);

index()docs allows you to pass a selector or DOM element as a parameter to work similarly to indexOf.

Upvotes: 1

Related Questions