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?
- Exclusive Author
- Author has had an Item Featured
- Author was Featured
- Author had a File in an Envato Bundle
- Has been a member for 5-6 years
- Sold between 100 000 and 250 000 dollars
- Repeatedly Helped protect Envato Marketplaces against copyright violations
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.