1

I've tried to get the offsetWidth and offsetHeight properties like so:

<div id="somediv" class="some_class_with_dimensions"></div><script...>alert(document.getElementById('somediv').offsetWidth);</script>

Unfortunately, on IE7 offsetWidth only works if i call in on window.onload, otherwise it just returns 0. Does anyone know any other way around this problem, because i need to immediately work with "somediv" just like in real browsers.

Marius
  • 3,976
  • 5
  • 37
  • 52
  • The closest I can test with is IE8 rendering in IE7 mode, and that works fine. Can you set up an example at jsbin or jsfiddle to demonstrate your issue? – lincolnk Aug 22 '11 at 18:48
  • The example that i've given indeed does work. The problem arises in a not-so-valid html that i have no control over with lots of tables etc. My theory is that IE doesn't know the width until it loads the parent elements. Anyway, ignore this since i had no other choice but to use dom readyness checks. – Marius Sep 09 '11 at 19:13
  • @Marius: If you found the solution, you should post it as an answer. – Jon Adams Sep 14 '11 at 15:08
  • @Mufasa: i didn't find a solution and i don't know the exact cause so i took the next best thing - the dom readiness. Don't think it's worth to be marked as an answer cause i'm not satisfied with it myself. – Marius Sep 24 '11 at 09:57
  • You're correct, it won't know the offset until it draws the page. There isn't another workaround to getting that offset value, but there may be a workaround to what you are/were trying to solve. But would need more data to address that. – Peter Oram Oct 18 '12 at 02:21

0 Answers0