473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

get height of DIV

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

myDivElement.style.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 25145

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

myDivElement.style.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.height;
height = height.split("px")[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.style.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.height;
height = height.split("px")[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(valueWithPX,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.javascript 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.getElementById("theDiv");
var width = theDiv.offsetWidth;
var height = theDiv.offsetHeight;

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.getElementById("theDiv");
var width = theDiv.offsetWidth;
var height = theDiv.offsetHeight;
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(valueWithPX,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.javascript 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
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...
10
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...
12
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">...
5
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...
5
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...
1
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...
1
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...
1
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...
1
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...
4
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;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.