Make DOM elements invisible during modification


When several properties of a DOM (Document Object Model) element must be modified, each style or content change will generate a repaint or a reflow. It is therefore usually more economical to:
- make the element invisible (set display to none) (1 reflow) - modify the element properties and then make it visible again (1 reflow)

Thus resulting in a maximum of 2 reflows.

Proceed as follows:

var elem = document.getElementById('foo'); = 'none'; // Generate 1 reflow        = '10em';  = 'auto';
// ... other changes... = 'block'; // Generate 1 reflow

In the end, only 2 reflows are needed instead of potentially 6 or 7.