Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can only obtain element height if browser not maximised 1

Status
Not open for further replies.

PeDa

Technical User
Oct 10, 2002
227
0
0
NL
My pages like [sample page ] run a function on loading
Code:
<body id=body onload='initialize()'>
in which I try to read the height (or other property) of elements. However the line
Code:
 alert(document.getElementById('map').style.height);
only returns a value if the browser is not maximised; if it is maximised, I see an empty popup. I don't understand this last result; any help appreciated.
 
Hi

JavaScript can only read the style values it set previously.

However you can obtain it through [tt]getComputedStyle[/tt] :
JavaScript:
[COLOR=orange]getComputedStyle[/color][teal]([/teal]document[teal].[/teal][COLOR=orange]getElementById[/color][teal]([/teal][i][green]'map'[/green][/i][teal])).[/teal]height

Or if your site uses jQuery, that is able to handle it :
JavaScript:
$[teal]([/teal][i][green]'#map'[/green][/i][teal]).[/teal][COLOR=orange]css[/color][teal]([/teal][i][green]'height'[/green][/i][teal])[/teal]


Feherke.
feherke.ga
 
Hello Feherke,

Thank you; just what is needed.

Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top