I had a related idea[1] about speeding up DOM removal operations, but
this post got me thinking: would it be possible to use setTimeout to
delay event and data removal altogether?
function kill() {
jQuery.event.remove( this );
jQuery.removeData( this );
};
$.fn.remove = function( selector ) {
if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
var removed = jQuery( "*", this ).add([this]);
setTimeout( function() { removed.each( kill ) }, 10);
if (this.parentNode)
this.parentNode.removeChild( this );
}
};
Not only would this speed DOM removal by delaying what is essentially
GC, but I think it could solve this problem too, since you could
simply use:
$('#foo').remove().clone();
as the clone operation would take place before the events and data are
removed, right?
Jed Schmidt
[1]
http://groups.google.com/group/jquery-dev/browse_thread/thread/5a1a124d773ed80d
On Jan 29, 2:24 pm, Ricardo Tomasi <[email protected]> wrote:
> This seems like a possible work-around:
>
> var foo = $('#foo').clone(true);
> $('#foo').remove();
>
> foo.appendTo('somewhere else later')
>
> Not removing the handlers and data would consume more memory I guess,
> there is no way to guess if it's gonna be reappended or not.
>
> On Jan 29, 7:54 am, Már Örlygsson <[email protected]> wrote:
>
> > `$("#foo").remove()` removes all event handlers and stored data.
>
> > But, sometimes I'd like to temporarily remove an element from the DOM
> > for later reinjection, in which case the event and data removal
> > becomes a nuisance.
>
> > Is there a way to do that in jQuery - aside from writing your own
> > `.removeTemp()` plugin?
>
> > `$("#foo").remove(true)`
> > `$("#foo").remove(selector, true)`
>
> > feels like a natural way to express this.
>
> > any thoughts?
>
> > --
> > Már Örlygsson
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---