I\'m sure the answer is no, but is it possible to determine the width of an element before it is appended to the DOM?
Once it\'s appended, I know I
Modified the code a bit. Here is a pure JS solution:
function measure(el, fn) {
var pV = el.style.visibility,
pP = el.style.position;
el.style.visibility = 'hidden';
el.style.position = 'absolute';
document.body.appendChild(el);
var result = fn(el);
el.parentNode.removeChild(el);
el.style.visibility = pV;
el.style.position = pP;
return result;
}
var div = document.createElement('div');
div.innerHTML = "Hello
";
alert(div.offsetHeight); // 0
alert(measure(div, function(el){return el.offsetHeight})); // 68