Only detach the incoming elements to replaceWith if they're DOM nodes. Fixes #5986.

This commit is contained in:
Noah Sloan 2010-02-01 21:48:05 -05:00 committed by jeresig
parent e76ba32ceb
commit 8660ea1ab6
2 changed files with 13 additions and 6 deletions

View file

@ -268,16 +268,17 @@ jQuery.fn.extend({
if ( this[0] && this[0].parentNode ) {
// Make sure that the elements are removed from the DOM before they are inserted
// this can help fix replacing a parent with child elements
if ( !jQuery.isFunction( value ) ) {
value = jQuery( value ).detach();
} else {
if ( jQuery.isFunction( value ) ) {
return this.each(function(i) {
var self = jQuery(this), old = self.html();
self.replaceWith( value.call( this, i, old ) );
});
}
if ( typeof value !== "string" ) {
value = jQuery(value).detach();
}
return this.each(function() {
var next = this.nextSibling, parent = this.parentNode;