jquery .ready and height of element

The document.ready event signals that the HTML DOM is ready for accessing via Javascript, but that doesn’t mean that the elements have already rendered.

In fact, that’s the whole shebang behind ready: it’s a means for you to start manipulating your document’s HTML DOM without having to wait for the page to finish loading. It’s safe to assume that at document.ready, your elements are not yet displayed on the page.

Now, that comes with a caveat: if the elements haven’t rendered yet, how can the browser / Javascript know what its resolving height is? .height() may give zero at document.ready because of this. It’s probably best to wait until load instead of ready when it comes to pulling box dimensions from the layout.

Leave a Comment