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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXTRACTING CSS DIMENSIONAL PROPERTIES 1

Status
Not open for further replies.

happyBanana

Programmer
Jan 4, 2012
1
HI,

sorry if this is a bit obvious - i have been away from web programming for a few years.

i am producing a table, to be used as a shopping trolly. the table is inside a layer. i want to change the height of the layer so that the table does not overflow but "grows" as table is added to. i was going to do use something like:

var requiredHeight = document.getElementById("table").style.height

then use parseInt and use result to set layer height.

the PROBLEM is, i cannot get the height of the table - i get a blank - presumably a null

i would be grateful for any help.
many thanks

 
Hi

Probably the [tt]height[/tt] property was not set previously by JavaScript. In that case JavaScript can neither get the property value.

However you can use [tt]getComputedStyle()[/tt] in standard compliant browsers :
JavaScript:
[COLOR=darkgoldenrod]getComputedStyle[/color][teal]([/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'table'[/i][/green][teal])).[/teal]width
Or use Peter-Paul Koch's getStyle() function from his Get Styles article :
JavaScript:
[COLOR=darkgoldenrod]getStyle[/color][teal]([/teal][green][i]'table'[/i][/green][teal],[/teal][green][i]'width'[/i][/green][teal])[/teal]
Or use jQuery :
JavaScript:
$[teal]([/teal][green][i]'#table'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]width[/color][teal]()[/teal]


Feherke.
 
Why so complex, merely giving your layer a height set to auto will make it grow or shrink with its contents.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top