Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1135 If I initially set the height of a DIV to zero, then I add some text to this DIV the DIV resizes itself, how can I get the new height of the DIV?

You are here: irt.org | FAQ | DHTML | Q1135 [ previous next ]

Try:

<script language="JavaScript"><!--
function update() {
    if (document.all)
        document.all('myLayer').innerHTML = 'some text';
    else if (document.layers) {
        document.layers['myLayer'].document.open();
        document.layers['myLayer'].document.writeln('some text');
        document.layers['myLayer'].document.close();
    }
}

function size() {
    if (document.layers)
        alert('height = ' + document.layers['myLayer'].document.height);
    else if (document.all)
        alert('height = ' + document.all['myLayer'].offsetHeight);
}
//--></script>

<div id="myLayer" style="position:absolute; height:0" height="0"></div>

<br><br><br>

<form>
<input type="button" value="Update" onClick="update()">
<input type="button" value="Size?" onClick="size()">
</form>

Feedback on 'Q1135 If I initially set the height of a DIV to zero, then I add some text to this DIV the DIV resizes itself, how can I get the new height of the DIV?'

©2018 Martin Webb