I have used outerHeight
and outerWidth
on many places. Now, after jQuery 1.8 was released I have met a lot of issues caused by object return instead of its size.
For example:
$('#stackoverflowdiv').Height() // returns 100 px
$('#stackoverflowdiv').outerHeight() // returns "stackoverflowdiv" div
The only thing that I have found to fix this was to use "true/false" in the function as follows but the I get the same results as the standard width()
and height()
functions:
$('#stackoverflowdiv').outerHeight(true) // returns 100 px
$('#stackoverflowdiv').outerHeight(false) // returns 100 px
Has anyone knew why this is not working any more or other way to get the height/width of element + its margins.
EDIT: I started to believe that this is caused because I am selecting elements in iframe using contents()
function. I will try to make a demo.
JQuery 1.8
height()
,innerHeight()
,outerHeight()
andouterHeight(true)
work as expected:DEMO - Working height methods
The demo above is using a div:
With the following CSS:
Using this script:
Resulting in the following:
outerHeight
only returns an integer ornull
according to the jQuery DOCs.There must be something else in your code futzing with your output and making you see the div element.
It only works if I do
.outerHeight(1);
not.outerHeight(true);
It is working fine mate, i can't be sure without seeing your html and css but you can inspect this example and examine it is working fine on jQuery 1.8.0
Here is working jsFiddle.
jQuery:
css:
Are you sure that you forgot use a semicolon or define
document.ready
? Or worse forgot to definemargin
orborder
?This is actually a known jQuery bug that you can read about here.
I'm experiencing it with no parameter and the fix is setting the parameter (even though there's a default {false}), but I was able to break Barlas' fiddle by replacing the true parameter with 1 and false with 0. So don't do that if you are.
Do this:
Don't do this:
The best fix is to pass the Boolean parameter
true
orfalse
when callingouterHeight
orouterWidth
But..
If by any chance you don't have access to files which calls
outerHeight
or you don't want to edit allouterHeight
functions in your files, you can override the jQueryouterHeight
function like below to make it always pass thetrue
parameter