]> source.dussan.org Git - jquery.git/commitdiff
Make sure that the correct context is being passed in for replaceWith(fn). Fixes...
authorjeresig <jeresig@gmail.com>
Tue, 26 Jan 2010 00:22:28 +0000 (19:22 -0500)
committerjeresig <jeresig@gmail.com>
Tue, 26 Jan 2010 00:22:28 +0000 (19:22 -0500)
src/manipulation.js
test/unit/manipulation.js

index 37a8cfdfe038b327e43958e36a327f7ca6199813..8c188c2d565e83f853450f5ade778a6e20fa9ca2 100644 (file)
@@ -233,6 +233,12 @@ jQuery.fn.extend({
                        // this can help fix replacing a parent with child elements
                        if ( !jQuery.isFunction( value ) ) {
                                value = jQuery( value ).detach();
+
+                       } else {
+                               return this.each(function(i) {
+                                       var self = jQuery(this), old = self.html();
+                                       self.replaceWith( value.call( this, i, old ) );
+                               });
                        }
 
                        return this.each(function() {
index bbf9a3a25e747f720e5a23fa01a659c8cb052bc9..168c17c94b166435cf7ea6833d69691347a5ea56 100644 (file)
@@ -720,6 +720,16 @@ test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
 
 test("replaceWith(Function)", function() {
        testReplaceWith(functionReturningObj);
+
+       expect(16);
+
+       var y = jQuery("#yahoo")[0];
+
+       jQuery(y).replaceWith(function(){
+               equals( this, y, "Make sure the context is coming in correctly." );
+       });
+
+       reset();
 })
 
 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {