0

If I change some properties of some dom element in a function using javascript does the browser recalculate new position of elements immediately, before the function will be finished? That is, if I made one element invisible like obj.style.display = 'none' and read in the same functions properties of another element will they be recalculated?

Роман Коптев
  • 1,555
  • 1
  • 13
  • 35

1 Answers1

2

The answer is slightly more perverse than that. DOM updates in modern browsers are cached before being flushed at a certain interval... BUT, by inquiring into the DOM's state, you force the browser to perform the reflow there and then. It's part of the expected behaviour.

See an explanation here

So, if you want to defer the reflow, maybe get whatever computed values you require first. Otherwise, you should be ok. However, as it's part of a "standard", you may find implementations differ or stray.

Community
  • 1
  • 1
Jeff Watkins
  • 6,343
  • 16
  • 19