Reputation: 1615
If I insert some element into DOM tree
document.getElementById("settings-details-form").innerHTML = "<h2 id=\"ddd\">hello</h2>";
will the next line of JS code be executed before the DOM updates with the new element ?
What is the JavaScript execution model when doing DOM updates ?
Upvotes: 2
Views: 90
Reputation: 382304
When the next line is executed
Note that most browsers do optimizations : if you don't query the dimensions, for example, they won't be computed until they're needed (for the window rendering, ultimately). That's why it's faster to do a bunch of DOM changes when you don't query the DOM layout in the middle so that the reflow is computed only once (see Mozilla notes on HTML Reflow). The exact flow is highly browser engine dependent but functionally, whatever the browser, the next line of code will see an updated DOM.
Upvotes: 4