0

Is there a way to use jQuery to figure out the type of width an element has? Whether it's an exact width (like 200px) or a relative width (such as 20%).

I would also like to be able to detect if the element doesn't have any kind of width specifically set, either in the CSS file or inline styles.

How would I go about doing this? Thank you so much in advance!

Emphram Stavanger
  • 4,158
  • 9
  • 35
  • 63

1 Answers1

3

Check the value returned by .css('width') to get the applied rule. To determine if the style is inline, you'll need to use .prop('style') and get a-parsin' use (non-jQuery) .style.width (see element.style).

In general, it is non-trivial to determine whether any given element style comes from explicitly set CSS, or implicitly computed style rules.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • I know I can use `.css('width')` to get the width, but how do I determine if it's a percentage or not? As for detecting non-computed values, I found this; http://stackoverflow.com/a/5830517/951402 -- would that work? – Emphram Stavanger Dec 30 '11 at 15:45