From: MORGAN Date: Tue, 16 Oct 2012 14:25:08 +0000 (-0400) Subject: Return correct index for no-arg index() calls. Fixes #10977. Closes gh-971 X-Git-Tag: 1.9.0b1~197 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4bb46f413a0e2f6933013b26d2aceddca6cf03f1;p=jquery.git Return correct index for no-arg index() calls. Fixes #10977. Closes gh-971 --- diff --git a/src/traversing.js b/src/traversing.js index 4c58ae0b8..d92bec4cb 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -112,7 +112,7 @@ jQuery.fn.extend({ // No argument, return index in parent if ( !elem ) { - return ( this[0] && this[0].parentNode ) ? this.prevAll().length : -1; + return ( this[0] && this[0].parentNode ) ? this.first().prevAll().length : -1; } // index in selector diff --git a/test/unit/traversing.js b/test/unit/traversing.js index dd957c28b..b93bede29 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -651,3 +651,12 @@ test("eq('-1') #10616", function() { equal( $divs.eq( "-1" ).length, 1, "The string '-1' returns a selection that has length 1" ); deepEqual( $divs.eq( "-1" ), $divs.eq( -1 ), "String and number -1 match" ); }); + +test("index(no arg) #10977", function() { + expect(1); + + var $list = jQuery(""); + jQuery("#qunit-fixture").append( $list ); + strictEqual ( jQuery( "#indextest li:not(.one,.two)" ).index() , 0, "No Argument Index Check" ); + $list.remove(); +});