From: samuelberthelot on
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

From: web.dev on

samuelberthelot(a)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];

From: samuelberthelot on
Thanks for the reply. I thought I could avoid having to do that... ok
then.
web.dev wrote:

> samuelberthelot(a)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];

From: Randy Webb on
samuelberthelot(a)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/
From: Dustin on
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.

 |  Next  |  Last
Pages: 1 2
Prev: google pop-up blocker..
Next: Formfield not updated