Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10159 closed bug (wontfix)

.outerHeight() returns positive value for <script> elements

Reported by: yelo3 Owned by: yelo3
Priority: low Milestone: None
Component: dimensions Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:


I think I have found a bug in the .outerHeight() jquery function. I'm trying to the the height of the children of <body>, and it appears that <script> tags have a height > 0 (in this case I get 20, in chrome browser). This is not expected: in my opinion they should have a height = 0.


<html> <head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"> </script> <script type="text/javascript">

$(document).ready(function() {

var children = $(document.body).children();

for (i=0; i<children.length; i++) {

height = $(children[i]).outerHeight(true); console.log("height=" + height);




</head> <body>

<script type="text/javascript"> var a=1; var b=2; var c=3; </script>


<p>hello1</p> <p>hello2</p> <p>hello3</p>


</body> </html>

Change History (10)

comment:1 Changed 11 years ago by timmywil

Component: unfileddimensions
Owner: set to yelo3
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 11 years ago by yelo3

Status: pendingnew

I've done what you requested:


comment:3 Changed 11 years ago by Rick Waldron

Further, clearer reduction:


Last edited 11 years ago by Rick Waldron (previous) (diff)

comment:4 Changed 11 years ago by yelo3


also <style> tag is affected

comment:5 Changed 11 years ago by dmethvin

Status: newopen

comment:6 Changed 11 years ago by mikesherov

This happens because the width/height cssHook does a visibility swap when it encounters an element with no offsetWidth/offsetHeight. It reports a value because even style and script tags can get width/height when they are absolutely positioned and given display:block.

Two options:

  1. needsdoc that it reports weird values for style/script
  2. before visibilty swapping, detect nodeName "STYLE" or "SCRIPT", which begs the question of "what other elements should always report zero besides style and script?".

I'll open a PR just in case we want to go with option 2.

comment:7 Changed 11 years ago by timmywil

I'm inclined to say needsdocs. It seems pretty obvious that one shouldn't call width/height on style or script tags. And why loop through all of the elements on the page? I can't actually see where that would be useful.

comment:8 Changed 11 years ago by mikesherov

Also is broken on input:hidden tags in chrome. I opened a PR just in case: https://github.com/jquery/jquery/pull/547

It's pretty small. Also, here's the perf... looks pretty good: http://jsperf.com/outerwidth-on-hidden-elements

comment:9 Changed 11 years ago by dmethvin

Keywords: needsdocs added
Resolution: wontfix
Status: openclosed

comment:10 Changed 11 years ago by addyosmani

Keywords: needsdocs removed

Initial docs added to http://api.jquery.com/height/. I've pinged Dave and Karl about turning the notes into a reusable.

Note: See TracTickets for help on using tickets.