aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-11-17 11:47:56 -0500
committerDave Methvin <dave.methvin@gmail.com>2011-11-17 11:47:56 -0500
commitdd845a2c0f63f97e74e4d490ee66e12e0bf180c5 (patch)
treed2a67f9c0eab037b5b29a6dee8b8fdcefac8b60e
parent7c2d6c8cd87ce62210ca9f72bf132d4b1a797940 (diff)
downloadjquery-dd845a2c0f63f97e74e4d490ee66e12e0bf180c5.tar.gz
jquery-dd845a2c0f63f97e74e4d490ee66e12e0bf180c5.zip
Fix #10812, let .before() and .after() work on empty collections.
-rw-r--r--src/manipulation.js4
-rw-r--r--test/unit/manipulation.js8
2 files changed, 10 insertions, 2 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 9baa04203..28d63b8a2 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -154,7 +154,7 @@ jQuery.fn.extend({
this.parentNode.insertBefore( elem, this );
});
} else if ( arguments.length ) {
- var set = jQuery(arguments[0]);
+ var set = jQuery.clean( arguments );
set.push.apply( set, this.toArray() );
return this.pushStack( set, "before", arguments );
}
@@ -167,7 +167,7 @@ jQuery.fn.extend({
});
} else if ( arguments.length ) {
var set = this.pushStack( this, "after", arguments );
- set.push.apply( set, jQuery(arguments[0]).toArray() );
+ set.push.apply( set, jQuery.clean(arguments) );
return set;
}
},
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 1c426a7c3..0e8941621 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -794,6 +794,14 @@ test("before(Function)", function() {
testBefore(functionReturningObj);
})
+test("before and after w/ empty object (#10812)", function() {
+ expect(2);
+
+ var res = jQuery( "#notInTheDocument" ).before( "(" ).after( ")" );
+ equal( res.length, 2, "didn't choke on empty object" );
+ equal( res.wrap("<div/>").parent().text(), "()", "correctly appended text" );
+});
+
test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(4);
var expected = "This is a normal link: bugaYahoo";