Reputation: 1137
I learned from Jquery performance guide(http://learn.jquery.com/performance/detach-elements-before-work-with-them/) that detaching element when working with them improve performance. But I want to know whether this will improve performance even when reading from DOM or only when processing the DOM?
Upvotes: 1
Views: 146
Reputation: 816900
It improves performance when you make modifications to the element that would cause reflows, i.e. the browser would have to recompute the layout of the element.
Reading the DOM usually does not cause reflows.
As far as I know, reading certain layout information (such as the offset of an element) can trigger reflows to ensure that the correct values are returned. But in such a case, you probably want the element to be part of the document since you might not get accurate information otherwise.
Upvotes: 4