How can I get the computed width of an element in Opera? In other browsers I can do this:
// getComputedStyle wrapper
function getStyle(element, styleProp) {
return element.currentStyle ? element.currentStyle[styleProp] :
getComputedStyle(element, null).getPropertyValue(styleProp);
}
...but this only sort of works on Opera. It returns "auto" for a lot of things instead of a useful pixel value.
Here's a live demo that expands some text to fit in a box. It doesn't work on Opera, because the computed width is auto
instead of a px
value as in other browsers.
How can I get more useful computed styles, such as the pixel width of an element, in Opera?
I realize that I can, in this case, use offsetWidth
instead of getting the computed style. I appreciate the advice, but the real point of this question is that I want to know how to get computed styles in Opera where the style is actually computed in units. I don't care about offsetWidth
for the purposes of this question.
$(glyph).width()
insteedgetStyle(glyph, 'width')
jsbin.com/ikatuc/2/edit#javascript,html,live Tested in Opera 10.63, IE6-8, Chrome, Firefox – Extravehicular