Skip to main content

Bug Tracker

Side navigation

#10159 closed bug (wontfix)

Opened August 29, 2011 07:33AM UTC

Closed December 06, 2011 06:35PM UTC

Last modified December 11, 2011 11:59PM UTC

.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:
Description

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.

THIS IS MY CODE.

<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);

}

});

</script>

</head>

<body>

<script type="text/javascript">

var a=1;

var b=2;

var c=3;

</script>

<div>

<p>hello1</p>

<p>hello2</p>

<p>hello3</p>

</div>

</body>

</html>

Attachments (0)
Change History (10)

Changed August 29, 2011 01:18PM UTC by timmywil comment:1

component: unfileddimensions
owner: → 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.

Changed August 29, 2011 04:03PM UTC by yelo3 comment:2

status: pendingnew

I've done what you requested:

http://jsfiddle.net/FrKyN/13/

Changed August 29, 2011 04:43PM UTC by rwaldron comment:3

_comment0: Further, clearer reduction: \ \ http://jsfiddle.net/rwaldron/FrKyN/14/1314636433269953

Further, clearer reduction:

http://jsfiddle.net/rwaldron/j6thc/

Changed August 29, 2011 05:52PM UTC by yelo3 comment:4

http://jsfiddle.net/FrKyN/15/

also <style> tag is affected

Changed August 29, 2011 09:37PM UTC by dmethvin comment:5

status: newopen

Changed October 13, 2011 12:52PM UTC by mikesherov comment:6

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.

Changed October 13, 2011 01:22PM UTC by timmywil comment:7

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.

Changed October 14, 2011 02:05AM UTC by mikesherov comment:8

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

Changed December 06, 2011 06:35PM UTC by dmethvin comment:9

keywords: → needsdocs
resolution: → wontfix
status: openclosed

Changed December 11, 2011 11:59PM UTC by addyosmani comment:10

keywords: needsdocs

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