Reputation: 79
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
Upvotes: 1
Views: 106
Reputation: 6696
Using jQuery
often greatly simplifies the development. Using it, you can achieve your goals by:
$(#tableId).height();
Upvotes: 1
Reputation: 6127
Change class
to id
for simplicity:
<div id="tableScroll">
JS
document.getElementById('tableScroll').style.height;
Upvotes: 1