- 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 );
+ }