- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
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.hide(); el.show();
or
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
- Item was Featured
- Author was Featured
- Author had a File in an Envato Bundle
- Has been a member for 4-5 years
- Sold between 100 000 and 250 000 dollars
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- India
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.
- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
Thanks dude 
