Vishal,
As it says in the jQuery API, jQuery.remove() returns jQuery , so you can do something like this:
var x = $('#myDiv').remove();
//.......
$('#myElement').append(x);//or .after() or .prepend() depending on how you need to insert x back into the DOM. Of course, like any javascript member, x must be in scope, or formally passed to a function that operates on it. If x is neither directly in scope, kept alive by closure nor global, then it will be inaccessible and/or lost to garbage collection.
If scope issues make things difficult, you could alternatively move myDiv inside a hidden DOM element (eg another div reserved for this purpose) from which it can be recovered at any point in the code regardless of scope (the DOM is effectivey global). The move in would typically be performed with .append() while the move back out would be performed with .append(), .after() or .prepend().Airshow
Airshow
WiFi Lounge Lizard
Moderator
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372