If you just want to hide / show the object from time to time, use jQuery .hide() and .show() . This is the simplest and as long as you are going to hold the object anyway, you can simply use .hide() and .show() . If an object does not consume huge amounts of memory, this should not be a problem.
.remove() (when saving and reinserting the same object back into the DOM later) will be of little use to you, since it destroys some data associated with the object, so you cannot easily reinsert it on the page.
.remove() , where you actually allow the previous object to be destroyed by the garbage collector and then recreate it again from scratch when necessary, this is the most efficient memory operation, but if it does not consume a lot of memory or you have a lot of them (for example, thousands ), itβs probably just more work to do it this way without any meaningful benefit.
.detach() (while saving and reinserting the same object back into the DOM later) will work, but it works more than .hide() and .show() , and to be honest, I rather doubt that you will find the difference between two parameters.
jfriend00
source share