aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2011-03-15 17:06:24 -0400
committerJohn Resig <jeresig@gmail.com>2011-03-15 17:06:24 -0400
commit0cf336d2c95809ef41d94131e629fd1767f054a0 (patch)
tree3a9e1cb61dbdf62201077190394de0f0a3d85e81
parentbd4468886d97edfb53342e1a10acb300d081ed27 (diff)
parent124acbfbc523614dc5835cfce2c82b867a59986f (diff)
downloadjquery-0cf336d2c95809ef41d94131e629fd1767f054a0.tar.gz
jquery-0cf336d2c95809ef41d94131e629fd1767f054a0.zip
Merge branch 'bug_6158' of https://github.com/jboesch/jquery into jboesch-bug_6158
-rw-r--r--src/manipulation.js4
-rw-r--r--test/unit/manipulation.js7
2 files changed, 8 insertions, 3 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index ba3169715..27f81cc24 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -261,7 +261,9 @@ jQuery.fn.extend({
}
});
} 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;
}
},
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 34425ed3a..ff3dff164 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -739,7 +739,7 @@ test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
});
var testReplaceWith = function(val) {
- expect(20);
+ expect(21);
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' );
@@ -800,6 +800,9 @@ var testReplaceWith = function(val) {
equals( set[0].nodeName.toLowerCase(), "span", "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");
// TODO: Work on jQuery(...) inline script execution
//$div.replaceWith("<div class='replacewith'></div><script>" +
@@ -827,7 +830,7 @@ test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
test("replaceWith(Function)", function() {
testReplaceWith(functionReturningObj);
- expect(21);
+ expect(22);
var y = jQuery("#yahoo")[0];