JQuery1.3.2 source code learning 8: index Function

Source: Internet
Author: User

// Determine the position of an element
// The matched set of elements
160 index: function (elem ){
// Locate the position of the desired element
Return jQuery. inArray (
// If it takes es a jQuery object, the first element is used
Elem & elem. jquery? Elem [0]: elem
, This );

The index function of row 160 is used to return the subscript of an element in the query result. The subscript starts from 0. If no matching element is found,-1 is returned.
Note: The inArray function is defined in row 1086.
1086 inArray: function (elem, array ){
1087 for (var I = 0, length = array. length; I <length; I ++)
1088 // Use === because on IE, window = document
1089 if (array [I] === elem)
1090 return I;
1092 return-1;
1093 },
This is a very simple function. check whether a specific element exists in the array. Pay attention to the 1,089th rows and use = to determine whether it is the same object.

Source: blog

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.