开发者

jQuery overall element index

http://api.jquery.com/index/

Is there a way to use jQuery index() method to find the index of an element related to the overall document?

I mean, if I have a bunch of img tags in a document, is there a way to know, regardless of their position in the document, their index?

example :

<body>
<img />
<div>
   <img />
   <div>
      <img />
   </div>
</div>
</body>

I've tried using $(window), $(body), $(document), but they all fail. I really n开发者_StackOverfloweed the overall index of the element.

Cheers!


index() returns the position in a given collection:

$('img').index('id');


Do you mean

$('img').index(imgElement);

or

$('*').index(imgElement);

?


$('*').index($('.someClass'))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜