I don't think the browser will actually display the DOM while the script is running, at least not in my experience.
I always added an element to its final position, measured it, and then hid it.
I never noticed that it flashed instantly. I would be interested to know what others think.
Sort of:
JQuery
var el = $('<div/>', {
html: 'hello',
css: {
padding: '10px'
}
});
var height = el.appendTo( $(document.body) ).height();
el.hide();
Plain
var el = document.createElement( 'div' );
el.style.padding = '10px';
el.innerHTML = 'hello';
document.body.appendChild( el );
var height = el.clientHeight;
el.style.display = 'none';
meouw source
share