Skip to content

Commit 54946db

Browse files
johnkpaulscottgonzalez
authored andcommitted
Fixes jquery#395, update index article with indended and 1.9+ behavior.
1 parent 8cc59c2 commit 54946db

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

page/using-jquery-core/understanding-index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ console.log( "Index: " + $foo.index() ); // 1
2626
2727
var $listItem = $( "li" );
2828
29-
// This implicitly calls .last()
30-
console.log( "Index: " + $listItem.index() ); // 3
31-
console.log( "Index: " + $listItem.last().index() ); // 3
29+
// This implicitly calls .first()
30+
console.log( "Index: " + $listItem.index() ); // 1
31+
console.log( "Index: " + $listItem.first().index() ); // 1
3232
3333
var $div = $( "div" );
3434
35-
// This implicitly calls .last()
36-
console.log( "Index: " + $div.index() ); // 4
37-
console.log( "Index: " + $div.last().index() ); // 4
35+
// This implicitly calls .first()
36+
console.log( "Index: " + $div.index() ); // 0
37+
console.log( "Index: " + $div.first().index() ); // 0
3838
```
3939

4040
In the first example, `.index()` gives the zero-based index of `#foo1` within its parent. Since `#foo1` is the second child of its parent, `index()` returns 1.
4141

42-
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();`.
42+
When `.index()` is called on a jQuery object that contains more than one element, it calculates the index of the first element.
4343

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

0 commit comments

Comments
 (0)