From 5afc93c436020f8ceabe8cab449f1c0030ba6ecd Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 20 Dec 2012 03:52:08 +0400 Subject: [PATCH] Fix #13094. Pass index to .before(fn) fn as documented. Close gh-1093. --- src/manipulation.js | 7 ++++--- test/unit/manipulation.js | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 062527708..5fec948cb 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -286,16 +286,17 @@ jQuery.fn.extend({ var fragment, first, scripts, hasScripts, node, doc, i = 0, l = this.length, + set = this, iNoClone = l - 1, value = args[0], isFunction = jQuery.isFunction( value ); // We can't cloneNode fragments that contain checked, in WebKit if ( isFunction || !( l <= 1 || typeof value !== "string" || jQuery.support.checkClone || !rchecked.test( value ) ) ) { - return this.each(function() { - var self = jQuery( this ); + return this.each(function( index ) { + var self = set.eq( index ); if ( isFunction ) { - args[0] = value.call( this, i, table ? self.html() : undefined ); + args[0] = value.call( this, index, table ? self.html() : undefined ); } self.domManip( args, table, callback ); }); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 35beb5267..86b26e040 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2238,3 +2238,11 @@ test( "insertAfter, insertBefore, etc do not work when destination is original e jQuery("#test4087-multiple").remove(); }); }); + +test( "Index for function argument should be received (#13094)", 2, function() { + var i = 0; + + jQuery("
").before(function( index ) { + equal( index, i++, "Index should be correct" ); + }); +}); -- 2.39.5