1

I'm coding a javascript scriptlet on which I'm resizing a DOM element. But I need to know if the element was originally sized absolutely or relatively.

Of corse I can read its clientWidth property, but it always returns an absolute integer. How can I know if it was originally specified by a percentage number in a CSS? Is there any CSS property -readable from javascript- containing the original width expression?

Little Santi
  • 8,563
  • 2
  • 18
  • 46
  • `position_prop = document.getElementById(id).style.postion;` – aa333 Aug 30 '15 at 00:23
  • See [this question](http://stackoverflow.com/questions/8387419/retrieving-percentage-css-values-in-firefox). Not sure if duplicate – Artyom Neustroev Aug 30 '15 at 00:27
  • maybe window.getComputedStyle(elm[, pseudoelement]), this will return a list of css styles that the browser deems as what you see (computed Styles). – sadiqevani Aug 30 '15 at 00:28
  • @sadiqevani Thank you. I've tried `window.getComputedStyle`, but it still returns always absolute values in "width" and "height" fields. – Little Santi Aug 30 '15 at 08:07

1 Answers1

1

If your width value is inside the tag you can use document.getElementById("id").style.width. But if your css is inside a tag style, that's going to make you use jquery for a quick solution or you are going to have to create your own function to extract this value, like this one: How to get an HTML element's style values in javascript?

Community
  • 1
  • 1
Lucas Piske
  • 370
  • 2
  • 16
  • Thank you. In the link you have posted, I've seen the exact solution I needed: `Element.currentStyle`. Unfortunately, it only works in IE. I guess I'll have to add extra parameters to my javascript function. – Little Santi Aug 30 '15 at 08:06