[Javascript]Knowing the height of an HTML element

Last update on September 1, 2009 10:44 AM by jak58
Published by jak58

[Javascript]Knowing the height of an HTML element









To determine the height of a HTML block using JavaScript, independently from the type browsers used, there are two methods:
  • element.offsetHeight
  • element.style.pixelHeight




The following code implement these above methods, allowing you to determine the height of a block HTML regardless of the browser used:

<script type="text/javascript">
<!--
var divHeight;
var obj = document.getElementById('id_element');

if(obj.offsetHeight)          {divHeight=obj.offsetHeight;}
else if(obj.style.pixelHeight){divHeight=obj.style.pixelHeight;}
//-->
</script>
Best answers for « Knowing the height of an HTML element » in :
Modifying the height of element HTML Show Modifying the height of element HTML The style property “height” can be used to modify the height of an html element in javascript. For this you can refer to the following: Below is an indication of how to do this...
Hyperlinks Show Introduction to anchors Hypertext links or hyperlinks (anchors) are HTML elements that, when clicked on, enable readers to visit a new address. Hyperlinked text is underlined by default. Hyperlinks are what connect web pages to one another. They...
How to create your own Website ShowHow to create your own Website What is HTML? Example 1: HTML Tags HTML Elements Basic HTML Tags to Remember Example 2 HTML Attributes and Values Example 3 Colour Tags Example 4 Text Formatting Example 5 HTML Division Tags Example...
How to clean up your website ShowHow to clean up your website Links There are available web creation software programs that allow one to create hassle free website that somehow contain useless comment tags or other useless HTML elements or sloppy editions that take much...
Defining the relative vertical height of an element ShowDefining the relative vertical height of an element Sometimes we want to define a vertical height of an element. It is simple, using fixed values (not pixels), but it's more complicated when using relative heights (percentage). This...
Download HTML Ebook Maker and Encrypter ShowAs its name suggests, this software will allow you to encrypt your HTML pages with a password. It supports the following files: HTML, image, flash, swf, video, Javascript and so forth. The encrypted files will be collected in a single .exe file....
HTML forms ShowForms Interactive forms let web page authors give their pages interactive elements, such as for receiving messages from their readers, much like the reply cards found in some magazines. The reader enters information by filling in fields or clicking...
Declaring a style sheet (CSS) ShowDeclaring a style sheet Style sheets are not directly integrated into the W3C's HTML recommendations. For this reason, you need to include elements in the HTML code indicating both the type of document, meaning the version of the HTML and CSS...
CSS - Style sheets ShowFont properties Property Value Description font-family Specific font (Arial, Times, Verdana) Familly (serif, sans-serif, fantasy, monospace, cursive) Defines one or more font names or font families. If multiple fonts are defined,...