Skip to content

Commit

Permalink
Make sure that the correct context is being passed in for replaceWith…
Browse files Browse the repository at this point in the history
…(fn). Fixes #5798.
  • Loading branch information
jeresig committed Jan 26, 2010
1 parent 9f17e70 commit 0b3165f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/manipulation.js
Expand Up @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions test/unit/manipulation.js
Expand Up @@ -720,6 +720,16 @@ test("replaceWith(String|Element|Array<Element>|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<Element>|jQuery)", function() {
Expand Down

0 comments on commit 0b3165f

Please sign in to comment.