06 May, 2011

FireFox 4 jQuery document height and width

I ran into a little problem the other day. I had some jQuery goodness running along just fine and dandy. Everything was Jake while using Chrome and Internet Explorer 9 and FireFox 3, but when I looked at the site using FireFox 4, it didn't work right.

After some aggravating trial and error, I discovered the culprit. See, in the jQuery documentation, they say you can use two methods to get the height and width of a document:

$(document).height();
$(document).css('height');

The former gives you just the pixel numbers, while the latter is supposed to give you the entire CSS height (i.e. "450" for the first, and "450px" for the second). The problem is, that FireFox 4 doesn't recognize $(document).css('height') - or width for that matter. So you have to get it with just the .height() command, and append 'px' to the end of it.

No comments: