Bug Tracker

Opened 9 years ago

Closed 9 years ago

#14545 closed bug (wontfix)

In-body style element returns nonzero dimensions

Reported by: bggardner Owned by:
Priority: low Milestone: None
Component: css Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:


In HTML5, it is now valid to have style tags outside the head tag. jQuery returns nonzero dimensions (height(), width(), innerHeight(), etc.) for a style element inside of the HTML body tag. In the head tag, the correct (zero) dimensions are returned. JavaScript's clientHeight and clientWidth properties are zero, as expected. Only by setting the style tag's style attribute to "height: 0; width: 0" (or doing so in a stylesheet) will jQuery return zero for the dimension functions.

I have seen this in all jQuery versions available at jsfiddle, using Chrome and Firefox, both on Windows 7 and Ubuntu 13.10.

Example: http://jsfiddle.net/wz4vW/4/

Change History (6)

comment:1 Changed 9 years ago by timmywil

Component: unfiledcss
Priority: undecidedlow
Status: newopen

This is valid. We're using swap here to ensure elements are not hidden when retrieving dimensions, but we can skip it for style elements.

comment:2 Changed 9 years ago by bggardner

This also occurs with script elements.

comment:3 Changed 9 years ago by grisendo

comment:4 Changed 9 years ago by m_gol

What is an example use case that this bug is hurting?

comment:5 Changed 9 years ago by grisendo

Not sure how the reporter noticed it, but I can imagine a scenario like this:

$('#some-id > *').each( ... if ($(this).height() > someValue) { ...

Last edited 9 years ago by grisendo (previous) (diff)

comment:6 Changed 9 years ago by dmethvin

Resolution: wontfix
Status: openclosed

See the discussion in https://github.com/jquery/jquery/pull/1445, there's a docs ticket.

Note: See TracTickets for help on using tickets.