473,836 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get height of DIV

Hi,
To get the height of my DIV, I do :

myDivElement.st yle.height, which returns "176px". I don't want that. I
want to get 176. How could I do that, which property should I use? (I
could do a string parsing, but what a pain....)

Thanks

Jul 5 '06 #1
8 25183

sa************* @googlemail.com wrote:
Hi,
To get the height of my DIV, I do :

myDivElement.st yle.height, which returns "176px". I don't want that. I
want to get 176. How could I do that, which property should I use? (I
could do a string parsing, but what a pain....)

Thanks
There is no property which would return you just the number, you will
have to do string parsing. One way of doing this could be the
following:

//assuming you have your element

var height = myDiv.style.hei ght;
height = height.split("p x")[0];

Jul 5 '06 #2
Thanks for the reply. I thought I could avoid having to do that... ok
then.
web.dev wrote:
sa************* @googlemail.com wrote:
Hi,
To get the height of my DIV, I do :

myDivElement.st yle.height, which returns "176px". I don't want that. I
want to get 176. How could I do that, which property should I use? (I
could do a string parsing, but what a pain....)

Thanks

There is no property which would return you just the number, you will
have to do string parsing. One way of doing this could be the
following:

//assuming you have your element

var height = myDiv.style.hei ght;
height = height.split("p x")[0];
Jul 5 '06 #3
sa************* @googlemail.com said the following on 7/5/2006 12:31 PM:
Thanks for the reply. I thought I could avoid having to do that... ok
then.
valueWithoutPX = parseInt(valueW ithPX,10);

P.S. This is in the FAQ.

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 5 '06 #4
Use the offsetWidth and offsetHeight properties. They are properties
of the element, not the elements style node.

var theDiv = document.getEle mentById("theDi v");
var width = theDiv.offsetWi dth;
var height = theDiv.offsetHe ight;

That works in IE6 and Firefox. I haven't tested it in other browsers.

Jul 5 '06 #5
Dustin wrote:
Use the offsetWidth and offsetHeight properties. They are properties
of the element, not the elements style node.
var theDiv = document.getEle mentById("theDi v");
var width = theDiv.offsetWi dth;
var height = theDiv.offsetHe ight;
This may not always work as expected, however.

offset* properties are always the outer dimensions - including padding and
borders.
However, in a page running in "strict mode" in IE or in standards-compliant
browsers, the specified style height of 176px does _not_ include padding and
borders. So the style height and the offsetHeight may actually be different,
and you need to use the one you actually want.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 5 '06 #6
Thanks but it doesn't seem to work with FF :(
Randy Webb wrote:
sa************* @googlemail.com said the following on 7/5/2006 12:31 PM:
Thanks for the reply. I thought I could avoid having to do that... ok
then.

valueWithoutPX = parseInt(valueW ithPX,10);

P.S. This is in the FAQ.

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 6 '06 #7
sa************* @googlemail.com wrote:
Thanks but it doesn't seem to work with FF :(
The phrase "doesn't work" is meaningless.
See http://www.javascripttoolbox.com/clj/#getanswers

3. Give an accurate error message or description of what failed. Never use
the words "doesn't work". Saying that something "doesn't work" gives no
information about what was supposed to happen and specifically what happened
instead. Give more detail.

parseInt("150px ",10)

will most certainly return 150 in FF, for example.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 6 '06 #8
Sorry I was being lazy in the description of the error...
indeed it returns 150 so I had to convert it to a string and add 'px'.
All works fine now
thank you
Matt Kruse wrote:
sa************* @googlemail.com wrote:
Thanks but it doesn't seem to work with FF :(

The phrase "doesn't work" is meaningless.
See http://www.javascripttoolbox.com/clj/#getanswers

3. Give an accurate error message or description of what failed. Never use
the words "doesn't work". Saying that something "doesn't work" gives no
information about what was supposed to happen and specifically what happened
instead. Give more detail.

parseInt("150px ",10)

will most certainly return 150 in FF, for example.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12225
by: Paul | last post by:
Hi, I'm wondering if someone out there can help me overcome this quandary. I need to be able to calculate the height of the current page. I need to calculate the height of the page in pixels after all images and text have been displayed. This is the area that the visitor can 'scroll' up and down in. I have already calculated the height of the useable part of the browser using: document.body.clientHeight
10
7864
by: John | last post by:
I have a table with two rows. On the first row is a text box and in the second row is an image. I have set the table cellpadding to 0 and cellspacing to 0. The table is leaving extra spaces in the rows on the top and bottom of the picture and image. I need to make the height of the rows to be the same as the textbox and image. How do I do this? I have tried even setting the height of the table and all the <td> and <tr> tags to 1 but have...
12
6748
by: Stanimir Stamenkov | last post by:
Here are two cases regarding inline-level elements' line-height, padding and background, which I doesn't understand: <div style="background: black; color: white; line-height: 1.5"> <span>Abc</span> <span style="background: white; color: black; line-height: 3">Abc</span> <span>Abc</span> </div>
5
2915
by: Secret Guy | last post by:
Because of my experience posting various places over the last couple of weeks: I'm expecting to be greated with hostility for asking about concepts instead of "practical" things, since that has been my experience for years and decades. Maybe I'm projecting hostility. I don't know. How can I ask about theory and concepts without offending people? I'll just continue asking and cross my fingers: According to the 2.1 spec, regarding...
5
18734
by: Kevin Myers | last post by:
How can one obtain obtain the height of a MS Access 2K form? There is a width property, but I don't see a corresponding height property. I need to obtain the height of the form so that I can dynamically resize an object on the form in the form's Form_Resize method when a user resizes the form, both horizontally and vertically. Thanks, s/KAM
1
3381
by: polocar | last post by:
Ciao a tutti, leggendo qua e là per il forum ho scoperto che non sono l'unico ad avere questo problema. Se si inserisce un controllo ComboBox in un form di C#, non è possibile impostare la sua altezza ad un valore diverso da 21. Forse, cambiando la dimensione del font, si potrebbe riuscire a cambiare anche l'impostazione dell'altezza... (MS farebbe comunque meglio ad introdurre per il ComboBox una proprietà AutoSize impostabile a "false"...
1
6492
by: Mike Collins | last post by:
I am trying to create some pages and have them take 100% of the window, but I cannot get 100% to work. If I set the height of my div, the page displays a scroll bar and it looks like I set the height to about 150%. I tried using CSS, now I am trying tables. Can someone show me where I am mixing things up? Thanks. --Master Sheet <%@ Master Language="C#" AutoEventWireup="true" CodeFile="master.master.cs" Inherits="pts" %>
1
3368
by: mascouta | last post by:
I have a lot of problems with IE browser, one of them is described in this topic. in my website i have div Calculator with background image. it displayed perfectly with Firefox browser however in IE browser the height of the layer increased and it shown longer than the regular height which makes troubles with the footer of the website. This is the CSS of the layer: .demo {position:absolute ; top:710px; left:380px; z-index:99; ...
1
5174
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in FF, IE6 and IE7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Employee Listing </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords"...
4
2488
by: AAaron123 | last post by:
<body runat="server" id="MainBody"> <form id="form1" runat="server" style="background-color:green; width: 100%; height: 100%"> <br /> Table1" runat="server" Style="background-color:Yellow; width: 100%; height: 90%" BorderColor="Maroon"
0
10862
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10560
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10607
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10262
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6986
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4468
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.