Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make sure that the correct context is being passed in for replaceWith…

…(fn). Fixes #5798.
  • Loading branch information...
commit 0b3165fd23ba4d240dd72f93d315bb5f7bf970e8 1 parent 9f17e70
John Resig jeresig authored

Showing 2 changed files with 16 additions and 0 deletions. Show diff stats Hide diff stats

  1. +6 0 src/manipulation.js
  2. +10 0 test/unit/manipulation.js
6 src/manipulation.js
@@ -233,6 +233,12 @@ jQuery.fn.extend({
233 233 // this can help fix replacing a parent with child elements
234 234 if ( !jQuery.isFunction( value ) ) {
235 235 value = jQuery( value ).detach();
  236 +
  237 + } else {
  238 + return this.each(function(i) {
  239 + var self = jQuery(this), old = self.html();
  240 + self.replaceWith( value.call( this, i, old ) );
  241 + });
236 242 }
237 243
238 244 return this.each(function() {
10 test/unit/manipulation.js
@@ -720,6 +720,16 @@ test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
720 720
721 721 test("replaceWith(Function)", function() {
722 722 testReplaceWith(functionReturningObj);
  723 +
  724 + expect(16);
  725 +
  726 + var y = jQuery("#yahoo")[0];
  727 +
  728 + jQuery(y).replaceWith(function(){
  729 + equals( this, y, "Make sure the context is coming in correctly." );
  730 + });
  731 +
  732 + reset();
723 733 })
724 734
725 735 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {

0 comments on commit 0b3165f

Please sign in to comment.
Something went wrong with that request. Please try again.