Skip to content

Commit

Permalink
Merge branch 'bug_6158' of https://github.com/jboesch/jquery into jbo…
Browse files Browse the repository at this point in the history
…esch-bug_6158
  • Loading branch information
jeresig committed Mar 15, 2011
2 parents bd44688 + 124acbf commit 0cf336d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/manipulation.js
Expand Up @@ -261,7 +261,9 @@ jQuery.fn.extend({
} }
}); });
} else { } else {
return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ); return this.length ?
this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) :
this;
} }
}, },


Expand Down
7 changes: 5 additions & 2 deletions test/unit/manipulation.js
Expand Up @@ -739,7 +739,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
}); });


var testReplaceWith = function(val) { var testReplaceWith = function(val) {
expect(20); expect(21);
jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' )); jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
ok( jQuery("#replace")[0], 'Replace element with string' ); ok( jQuery("#replace")[0], 'Replace element with string' );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' ); ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
Expand Down Expand Up @@ -800,6 +800,9 @@ var testReplaceWith = function(val) {
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equals( set.length, 1, "Replace the disconnected node." ); equals( set.length, 1, "Replace the disconnected node." );


var non_existant = jQuery('#does-not-exist').replaceWith( val("<b>should not throw an error</b>") );
equals( non_existant.length, 0, "Length of non existant element." );

var $div = jQuery("<div class='replacewith'></div>").appendTo("body"); var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
// TODO: Work on jQuery(...) inline script execution // TODO: Work on jQuery(...) inline script execution
//$div.replaceWith("<div class='replacewith'></div><script>" + //$div.replaceWith("<div class='replacewith'></div><script>" +
Expand Down Expand Up @@ -827,7 +830,7 @@ test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
test("replaceWith(Function)", function() { test("replaceWith(Function)", function() {
testReplaceWith(functionReturningObj); testReplaceWith(functionReturningObj);


expect(21); expect(22);


var y = jQuery("#yahoo")[0]; var y = jQuery("#yahoo")[0];


Expand Down

0 comments on commit 0cf336d

Please sign in to comment.