Skip to content

fixing issue#422 on wrong output in newer jQuery versions #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions page/using-jquery-core/understanding-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ In the first example, `.index()` gives the zero-based index of `#foo1` within it

Potential confusion comes from the other examples of `.index()` in the above code. When `.index()` is called on a jQuery object that contains more than one element, it does not calculate the index of the first element as might be expected, but instead calculates the index of the last element. This is equivalent to always calling `$jqObject.last().index();`.

As of versions greater than **1.8.3** the jQuery index implecitly call the `.first()`, so the result of the above code on versions greater than **1.8.3** will be

```
var $foo = $( "#foo1" );

console.log( "Index: " + $foo.index() ); // 1

var $listItem = $( "li" );

// This implicitly calls .first()
console.log( "Index: " + $listItem.index() ); // 1
console.log( "Index: " + $listItem.index().index() ); // 1

var $div = $( "div" );

// This implicitly calls .first()
console.log( "Index: " + $div.index() ); // 0
console.log( "Index: " + $div.first().index() ); // 0
```

## `.index()` with a String Argument

```
Expand Down