简体   繁体   English

dom元素的jQuery索引?

[英]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. DOM元素是li ,我需要它在列表中的位置。

Thanks! 谢谢!

EDIT: If what i'm doing is correct then something here is wrong, Touch events over two dom elements? 编辑:如果我正在做的是正确的,那么这里的东西是错的, 触摸事件超过两个dom元素?

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. jQuery比给你的长度属性,就像在数组上一样。

$(element).prevAll().length;

What you want is $('li').index(element); 你想要的是$('li').index(element);

index() docs allows you to pass a selector or DOM element as a parameter to work similarly to indexOf . index() docs允许您将选择器或DOM元素作为参数传递,以与indexOf类似地工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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