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

can't get height of table in ie5

Status
Not open for further replies.

pigsie

Programmer
Joined
Dec 19, 2000
Messages
307
Location
GB
Hi

I'm trying to get the size of a table. I have a table called grid (id="grid") but ...

getElementById('grid').getAttribute('height');

returns blank. I can get the width but not the height and I'm wondering if its because the table width is specified but not the height. Unfortunately due to a number of reasons this has to work/is not working on ie5. Does anyone know if this is a bug?

Thanks
 
Hello pigsie,

If the height and/or width are not explicitly set as table tag's attributes, getAttribute("height") or same "width" would return empty. In that case, I would suggest you retieve instead using properties clientHeight and clientWidth: (alert say)
[tt]
alert(getElementById('grid').clientHeight);
[/tt]
If there is border setting, say border=n (n some number), total height would be adding twice the border setting:
[tt]
totalHeight = clientHeight + 2 * bordersetting [green](this is not code)[/green]
[/tt]
regards - tsuji
 
Correction:

I meant sure
[tt] [blue]document.[/blue]getElementById('grid').clientHeight
[/tt]
- tsuji
 
Thanks

I guessed as much however the above code returns blank for the height in ie5, in the end I had to use a combination of different methods:

alert(document.getElementById('grid').getAttribute('width'));
alert(window.document.all.grid.clientHeight);

Which is the only combination which seemed to work for both height and width in ie5 and ie6.

Thanks
 
>>Which is the only combination which seemed to work for both height and width in ie5 and ie6

nope thre is one more:
alert(document.getElementById('grid').offsetHeight)
alert(document.getElementById('grid').offsetWidth)

Known is handfull, Unknown is worldfull
 
vbkris,

Thanks for the suggestions, unfortunately I just tested it in ie5 and

alert(document.getElementById('grid').offsetHeight)
alert(document.getElementById('grid').offsetWidth)

will return 0 for the height even if a height has been specified. It does however work in ie6.

Thanks

 
i will test it again and come back...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top