Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 4bb46f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/traversing.js
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/unit/traversing.js
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

congrats on your first pull, @morgangraphics 👏

Please sign in to comment.