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;
});
var testReplaceWith = function(val) {
- expect(15);
+ expect(17);
jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
ok( jQuery("#replace")[0], 'Replace element with string' );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
ok( jQuery("#first")[0], 'Replace element with element' );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
+ reset();
+ jQuery("#main").append('<div id="bar"><div id="baz">Foo</div></div>');
+ jQuery('#baz').replaceWith("Baz");
+ equals( jQuery("#bar").text(),"Baz", 'Replace element with text' );
+ ok( !jQuery("#baz")[0], 'Verify that original element is gone, after element' );
+
reset();
jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
ok( jQuery("#first")[0], 'Replace element with array of elements' );
test("replaceWith(Function)", function() {
testReplaceWith(functionReturningObj);
- expect(16);
+ expect(18);
var y = jQuery("#yahoo")[0];