views:

46

answers:

3

I am creating a table dynamically based on the number of rows returned from the server using struts. The table is created properly and I am trying to get the height value on the created table using any of the following:

document.getElementById('elementId').offsetHeight
jQuery("#elementId").css('height')
jQuery("#elementId").height()

I have run my code using Chrome and they all return the proper height of the table. The issue I am having is with Firefox. Any of these run with Firefox is always returning a value of 0.

I have tried placing the code in a $(document).ready(), $(window).load(), and in a window.load = function(){} call, but none of them are returning a value. When I run the code in Chrome it returns a value of 136 for the height and when I run the same code in Firefox, it returns a value of 0 every time.

Is there something I am missing? Any help would be greatly appreciated.

A: 

try wrapping the table in a div and get the height of the div.

Moin Zaman
A: 

It may be a case of how your setting the size on you table dynamically.

Try either of the following:

alert(document.getElementById("myElement").clientHeight);

alert(document.getElementById("myElement").style.height);
JonVD
Thanks for all the help. Using document.getElementById("myElement").style.height seems to work with Firefox and Chrome for the div element, but not the table element. I have my table wrapped in a scrollable div that I want to have a max height of 212px and if its less than that, I need to adjust the height of the div to the same height of the table so the scroll bar isn't still the same height of the div. Thanks for the help.
usherjer
Sorry, for forgot to mention that the table height doesn't return any value at all when using document.getElementById("myElement").style.height
usherjer
A: 

Moin is on to something - I had to wrap a table in a DIV to get its height. But if your next step is to SET the height this won't work in FF:

$("#ID").height(123)

You need to do this instead

$("#ID).css("height", 123)

NO idea why.

n8wrl