IE8 $('body').width() is 0 on $(window).load()

Posted by allicarn on Stack Overflow See other posts from Stack Overflow or by allicarn
Published on 2013-10-23T21:52:38Z Indexed on 2013/10/23 21:53 UTC
Read the original article Hit count: 101

On $(document).ready I run through a for loop twice and alert out the body's width ($('body').width();) each time through. I get a value I would expect (ex. 1092).

On $(window).load I run through another for loop twice, also alerting out the body's width each time through. I get 0 the first time through (and the page looks completely blank behind the alert), and then a value I would expect the second time through (ex. 1092).

This is an issue I am not able to replicate in a stripped-down example, nor any other browser (Chrome, Safari, Firefox, IE9, IE10).

Does anyone have any ideas, or other things that I could test for?

I am using $(window).load to cut up some divs based on their width, which is based on their font size, which is based on a webfont (which isn't necessarily loaded by the time $(document).ready fires).

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery