A quick note on the detach() method..

If the selector you use with detach() doesn't match any element in the dom, then JQuery will still return an object.

 

(function($){

$(document).ready(function(){

var obj = $("#someDivThatDoesntExist").detach();

alert(obj);
// shows that obj is an Object

alert(obj.length);
// shows that the length is 0
// (I could swear this returned 1 in an earlier version of jQuery)

alert(obj[0]);
// undefined
});

})(jQuery);