get height of div using css

W

Warren Thai

i have a cascading style sheet with this in it
*******************************
..menu
{
position : absolute;
width : 60px;
height : 50px;
background-color : #FFC0CB;
top : 71px;
visibility : hidden;
font-family : verdana;
font-size : 10pt;
border-color : black;
border-width : 2px;
border-style : solid;
}
******************************
i have in my html this:
******************************
<div id="menu_1" class="menu">
<a href="t1.html"> Item 1 </a><br/>
<a href="t2.html"> Item 2 </a><br/>
<a href="t3.html"> Item 3 </a>
</div>
*******************************
i have a javascript along with this html
that has this:
*********************************
var m1 = document.getElementById("menu_1");
function test()
{
alert(m1.style.height);
}
*********************************
when i run this function, it shows nothing.
if i use "m1.style.top" it works
but height it doesn't
why?
 
R

RobG

Warren said:
i have a cascading style sheet with this in it
*******************************
..menu
{
position : absolute;
width : 60px;
height : 50px;
background-color : #FFC0CB;
top : 71px;
visibility : hidden;
font-family : verdana;
font-size : 10pt;
border-color : black;
border-width : 2px;
border-style : solid;
}
******************************
i have in my html this:
******************************
<div id="menu_1" class="menu">
<a href="t1.html"> Item 1 </a><br/>
<a href="t2.html"> Item 2 </a><br/>
<a href="t3.html"> Item 3 </a>
</div>
*******************************
i have a javascript along with this html
that has this:
*********************************
var m1 = document.getElementById("menu_1");
function test()
{
alert(m1.style.height);
}
*********************************
when i run this function, it shows nothing.
if i use "m1.style.top" it works
but height it doesn't
why?

The method you tried will work if height is set inline, however if
using CSS rules you have to use currentStyle (IE and similar) and
getComputedStyle (others).

<script type="text/javascript">
var m1 = document.getElementById("menu_1");
function test(){
if ( m1.currentStyle ) {
alert(m1.currentStyle.height);
} else if ( document.defaultView.getComputedStyle ){
alert(document.defaultView.getComputedStyle(m1,'').height);
} else {
return;
}
}
</script>

Have a look here where I posted a 'getFontSize' function that you may
wish to modify if you want to do this frequently.


<URL:http://groups.google.com.au/group/c...4139a24?q=getFontSize&rnum=1#09fea96794139a24>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,054
Members
48,769
Latest member
Clifft

Latest Threads

Top