0

So i am reading the height of an element using .offsetHeight within a window.onload listener. This means that the html elements must have loaded. However, if i use the same code but instead of using the window.onload i use a setTimeout with a 100ms wait time, the offsetHeight is different (which appears to be the correct value). Why is this? I obviously don't want to be adding unnecessary load times onto my web pages, are there any work arounds?

P.s even when using a 50ms wait time the results are inconsistent.

Thanks in advance.

  • Please provide some [code snippets](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do). We can't debug something that doesn't exist. -> [How to Ask](https://stackoverflow.com/help/how-to-ask) -> [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Reyno Nov 24 '21 at 12:22
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 28 '21 at 17:07

0 Answers0