Code
1 $ ('lil'). Index (document. getelementbyid ('bar'); // 1. Pass a DOM object and return the index position of this object in the original set.
2 $ ('lil'). Index ($ ('# bar'); // 1, passing a jquery object
3 $ ('lil '). index ($ ('li: GT (0) '); // 1, transmits a set of jquery objects, and returns the index position of the first element in the original set of this object.
4 $ ('# bar'). Index ('lil'); // 1, pass a selector and return # position of bar in all Li
5 $ ('# bar'). Index (); // 1. If no parameter is passed, the index position of the element in the same generation is returned.
HTML:
<Ul>
<Li id = "foo"> Foo </LI>
<Li id = "bar"> bar </LI>
<Li id = "Baz"> Baz </LI>
</Ul>
It should have been the content of the API, but I can't remember it. There are too many usage cases.
In general, there are two usage types,
1. First select a set, then select a specific element for search
2. First select an element and then obtain its index in a specific set.
In 1st cases, you can pass DOM elements and jquery objects
In 2nd cases, you can only passSelectorIt's a selector, neither Dom nor jquery object!
Ignore the empty one.