From 3936d086fb6d4192a01209c0088a1258a21b1176 Mon Sep 17 00:00:00 2001 From: Ahmed Abdel Razzak Date: Sat, 14 Sep 2013 19:58:27 +0200 Subject: [PATCH 1/2] updating Understand-index.md adding version 1.10.2 code result as it changed than 1.9.1 as of version 1.10.2 the index uses the .first method instead of .last check the code in the .min.js attached `index:function(e){return e?"string"==typeof e?x.inArray(this[0],x(e)):x.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1}` --- page/using-jquery-core/understanding-index.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/page/using-jquery-core/understanding-index.md b/page/using-jquery-core/understanding-index.md index 823c8f04..0984f163 100644 --- a/page/using-jquery-core/understanding-index.md +++ b/page/using-jquery-core/understanding-index.md @@ -41,6 +41,27 @@ 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 **jQuery version 1.10.2** the above code would produce the following result + +``` +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.first().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 ``` From 5f21c388d3c8e6b076572b2b5960576f97e2618a Mon Sep 17 00:00:00 2001 From: Ahmed Abdel Razzak Date: Sun, 15 Sep 2013 02:55:55 +0200 Subject: [PATCH 2/2] fixing wrong output on newer versions you can verify the code responsible for this behaviour change in any version > 1.9.0b1 i attached the code sample here ``` index: function(e) { return e ? "string" == typeof e ? b.inArray(this[0], b(e)) : b.inArray(e.jquery ? e[0] : e, this) : this[0] && this[0].parentNode ? this.first().prevAll().length : -1 }, ``` --- page/using-jquery-core/understanding-index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/page/using-jquery-core/understanding-index.md b/page/using-jquery-core/understanding-index.md index 0984f163..3b547b2b 100644 --- a/page/using-jquery-core/understanding-index.md +++ b/page/using-jquery-core/understanding-index.md @@ -41,7 +41,9 @@ 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 **jQuery version 1.10.2** the above code would produce the following result + +As of **jQuery version 1.9.0b1** the `.index()` functions uses `.first()` instead of `.last()`, +so on versions greater than **1.9.0b1** the above code would produce the following result. ``` var $foo = $( "#foo1" );