1

I have a dynamic table with height 300 px and overflow-y: scroll such that table will have a vertical scroller. If there are less rows I want to change the height of the table so that there will be no space in the table and a scroll.

I was trying to retrieve the height of the table but it comes as 0. when I looked into the trace I can see that element has height. I tried

document.getElementById("myDiv").style.height  
document.getElementById("myDiv").offsetHeight  
document.getElementById("myDiv").clientHeight

but none of them return a valid value to height.

here is my Css:

.tableSroll {    
    overflow: auto;    
}  
.myDiv {  
    display: block;  
    width: 900px;  
    height: 300px;  
    overflow:auto;  
    overflow-y: scroll;  
}  

.ai-table-list-items {  
    pading: 50px;  
    width: 100%;  
}  

Here is my HTML:

<div class="tableScroll">

    <div class= "myDiv" id= "myDiv" >  

         <table class="ai-table-list-items">.....</table>  

    </div>  

</div>   

can anybody please help me to retrieve the height of the div in Firefox? I have been searching for it since a long time..

Thanks in advance,
Pbale

4

2 回答 2

1

为简单起见更改classid

<div id="tableScroll">

JS

document.getElementById('tableScroll').style.height;
于 2012-08-09T16:53:21.670 回答
1

经常使用jQuery大大简化了开发。使用它,您可以通过以下方式实现目标:

$(#tableId).height();
于 2012-08-09T16:58:03.380 回答