aboutsummaryrefslogtreecommitdiffstats
path: root/src/manipulation.js
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-09-14 22:09:42 +0000
committerJohn Resig <jeresig@gmail.com>2009-09-14 22:09:42 +0000
commit173c1477ae6efc4c2eeb7131ba0646c4e1323975 (patch)
tree5fa02dc3ed17c1ca8661555792b6f74226b17cd5 /src/manipulation.js
parentbca82254137a161094377b2d8189c2d9d5906a0f (diff)
downloadjquery-173c1477ae6efc4c2eeb7131ba0646c4e1323975.tar.gz
jquery-173c1477ae6efc4c2eeb7131ba0646c4e1323975.zip
Added support for .before(), .after(), and .replaceWith() on disconnected DOM nodes. Fixes bug #3940.
Diffstat (limited to 'src/manipulation.js')
-rw-r--r--src/manipulation.js32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 501383816..4746dc83b 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -106,15 +106,29 @@ jQuery.fn.extend({
},
before: function() {
- return this.domManip(arguments, false, function(elem){
- this.parentNode.insertBefore( elem, this );
- });
+ if ( this[0] && this[0].parentNode ) {
+ return this.domManip(arguments, false, function(elem){
+ this.parentNode.insertBefore( elem, this );
+ });
+ } else {
+ var set = jQuery.isFunction(arguments[0]) ?
+ jQuery( arguments[0]() ) :
+ jQuery.apply(jQuery, arguments);
+
+ return this.pushStack( set.add( this ), "before", arguments );
+ }
},
after: function() {
- return this.domManip(arguments, false, function(elem){
- this.parentNode.insertBefore( elem, this.nextSibling );
- });
+ if ( this[0] && this[0].parentNode ) {
+ return this.domManip(arguments, false, function(elem){
+ this.parentNode.insertBefore( elem, this.nextSibling );
+ });
+ } else {
+ return jQuery.isFunction(arguments[0]) ?
+ this.add( arguments[0]() ) :
+ this.add.apply( this, arguments );
+ }
},
clone: function( events ) {
@@ -193,7 +207,11 @@ jQuery.fn.extend({
},
replaceWith: function( value ) {
- return this.after( value ).remove();
+ if ( this[0] && this[0].parentNode ) {
+ return this.after( value ).remove();
+ } else {
+ return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
+ }
},
detach: function( selector ) {