简体   繁体   中英

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.

$(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;

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 .

这适用: index = $(element).index()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM