Skip to content

Commit 5afc93c

Browse files
markelogdmethvin
authored andcommitted
Fix #13094. Pass index to .before(fn) fn as documented. Close jquerygh-1093.
1 parent 96a349e commit 5afc93c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/manipulation.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -286,16 +286,17 @@ jQuery.fn.extend({
286286
var fragment, first, scripts, hasScripts, node, doc,
287287
i = 0,
288288
l = this.length,
289+
set = this,
289290
iNoClone = l - 1,
290291
value = args[0],
291292
isFunction = jQuery.isFunction( value );
292293

293294
// We can't cloneNode fragments that contain checked, in WebKit
294295
if ( isFunction || !( l <= 1 || typeof value !== "string" || jQuery.support.checkClone || !rchecked.test( value ) ) ) {
295-
return this.each(function() {
296-
var self = jQuery( this );
296+
return this.each(function( index ) {
297+
var self = set.eq( index );
297298
if ( isFunction ) {
298-
args[0] = value.call( this, i, table ? self.html() : undefined );
299+
args[0] = value.call( this, index, table ? self.html() : undefined );
299300
}
300301
self.domManip( args, table, callback );
301302
});

test/unit/manipulation.js

+8
Original file line numberDiff line numberDiff line change
@@ -2238,3 +2238,11 @@ test( "insertAfter, insertBefore, etc do not work when destination is original e
22382238
jQuery("#test4087-multiple").remove();
22392239
});
22402240
});
2241+
2242+
test( "Index for function argument should be received (#13094)", 2, function() {
2243+
var i = 0;
2244+
2245+
jQuery("<div/><div/>").before(function( index ) {
2246+
equal( index, i++, "Index should be correct" );
2247+
});
2248+
});

0 commit comments

Comments
 (0)