Skip to content
Permalink
Browse files

Return correct index for no-arg index() calls. Fixes #10977. Closes g…

  • Loading branch information...
morgangraphics authored and rwaldron committed Oct 16, 2012
1 parent ed9e344 commit 4bb46f413a0e2f6933013b26d2aceddca6cf03f1
Showing with 10 additions and 1 deletion.
  1. +1 −1 src/traversing.js
  2. +9 −0 test/unit/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
@@ -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("<ul id='indextest'><li>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>");
jQuery("#qunit-fixture").append( $list );
strictEqual ( jQuery( "#indextest li:not(.one,.two)" ).index() , 0, "No Argument Index Check" );
$list.remove();
});

1 comment on commit 4bb46f4

@mikesherov

This comment has been minimized.

Copy link
Member

commented on 4bb46f4 Oct 16, 2012

congrats on your first pull, @morgangraphics 👏

Please sign in to comment.
You can’t perform that action at this time.