From c4acf8fe359074ddc6dda9e84e52cbed6417ee29 Mon Sep 17 00:00:00 2001 From: Ahmed Abdel Razzak Date: Sun, 15 Sep 2013 14:59:21 +0200 Subject: [PATCH] fixing issue#422 on wrong output in newer jQuery versions --- page/using-jquery-core/understanding-index.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/page/using-jquery-core/understanding-index.md b/page/using-jquery-core/understanding-index.md index 823c8f04..9f1ba925 100644 --- a/page/using-jquery-core/understanding-index.md +++ b/page/using-jquery-core/understanding-index.md @@ -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 ```