Jquery index usage

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.