I am building the diagram component in JS. It has two layers rendered separately: foreground and background. In order to determine the required size of the background:
- render the foreground
- measure the height of the result
- render the foreground and the background together
In code it looks like this:
var foreground = renderForegroundIntoString();
parentDiv.innerHTML = foreground;
var height = parentDiv.children[0].clientHeight;
var background = renderBackgroundIntoString(height);
parentDiv.innerHTML = foreground + background;
Using IE7, this is a piece of cake. However, Firefox2 is not really willing to render the parentDiv.innerHTML right away, therefore I cannot read out the foreground height. Could someone enlighten me on when does Firefox execute the rendering and how can I delay my background generation till foreground rendering is completed, or any alternative way to determine the height of my foreground elements?
[Appended after testing Dan's answer (thanx Dan)]
Within the body of the callback method (called back by setTimeout(...)) I can see, the rendering of the innerHTML is still not complete.