|
Prev: google pop-up blocker..
Next: Formfield not updated
From: samuelberthelot on 5 Jul 2006 11:52 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 5 Jul 2006 12:29 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 5 Jul 2006 12:31 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 5 Jul 2006 12:38 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 5 Jul 2006 12:46
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. |