How can I get a height
element via JavaScript, if it is registered in the style of style.css
?
style.css:
. Menu_BotTom {
HEIGHT: 100px;
}
index.php:
& lt; div id = "menu_bottom" class = "menu_bottom" & gt;
& lt; script type = "text / javascript" & gt;
Alert (document.getelementByid ("menu_bottom"). style.Height);
& lt; / script & gt;
It is necessary that the message alert (...)
showed the height of this item (just a number, without a unit of measure).
Answer 1, Authority 100%
The easiest way to use jQuery :
$ ('# menu_bottom'). Height ();
without jQuery can be used:
var h = document.getelementbyid ('menu_bottom'). ClientHeight;
VAR H = Document.getelementByid ('menu_bottom'). offsetHeight;
VAR H = Document.getelementByid ('menu_bottom'). ScrollHeight;
clientheight Content height with padding fields, but without a scroll bar.
offsetheight “external” block height, including frames.
scrollheight Complete internal height, including scrolled area.
Answer 2, Authority 25%
var test = document.getelementbyid ("menu_bottom");
var height = window.getcomputedStyle (Test, NULL) .Height;
Alert (Height);
for ie:
var body = document.getelementsbytagname ("body");
var bg = body.currentStyle.Height;
Answer 3, Authority 25%
For JS
Snacking styles, so use GetComputedStyle
Answer 4
alert (document.getelementbyid ('menu_bottom'). ClientHeight);