Commit 4bb46f41 authored by MORGAN's avatar MORGAN Committed by Rick Waldron

Return correct index for no-arg index() calls. Fixes #10977. Closes gh-971

parent ed9e3448
...@@ -112,7 +112,7 @@ jQuery.fn.extend({ ...@@ -112,7 +112,7 @@ jQuery.fn.extend({
// No argument, return index in parent // No argument, return index in parent
if ( !elem ) { 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 // index in selector
......
...@@ -651,3 +651,12 @@ test("eq('-1') #10616", function() { ...@@ -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" ); 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" ); 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();
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment