Let’s say I have two elements where one is always visible and the other is always hidden. And their visibility swaps on multiple occasions. What is the fastest jQuery approach?
el.detach(); // need to use detach instead of remove el.appendTo(parent);
My instincts tell me that append/detach is a bigger performance hit than hide/show. But on the other hand, my guess is that hide() probably doesn’t release memory and detach() could. Any thoughts?
Performance test says ‘detach’ is better than ‘hide’ for elements with text content. But not sure if this works same way for image / canvas and nested elements.
Generally detach is a best practice not just to show/hide but reduces dom operation in the situations when too many changes needed on element/children.