[jQuery] an ajax load selector function to replace element

[jQuery] an ajax load selector function to replace element


I kept having to do
$('#content').load(url + " #content");
but ended up having
<div id="content">
<div id="content">
What i ready wanted was to completely replace the element with
selected content from an ajax load, hence,
$('#content).replace(url);
/**
* ajax load content and replace self
* replaced object must have 'id'
*/
jQuery.fn.replace = function( url, params, callback){
    var id = this.get(0).id;
    if (id) url += " #"+id;
    else {alert('replace object must have id!');}
    callback = callback || function(){};
    var self = this;
    $('<div>').load(url, params, function(){
            self.before($(this).find('#'+id)).remove();
            callback.apply(this,arguments);
    });
}
Hope someone experienced with jQuery can clean this up or suggest
another way.