javascript - Consistency of `element.style.width` across browsers -
if have html
<div id="container"> <div class="foo" style="width:75%;">bar!</div> </div>
and if write javascript (assuming jquery benefit of question)
alert( $("#container .foo")[0].style.width );
it should alert "75%". output consistent in every "modern" browsers? if not, popular non-standard browsers (even ie) fail return correct value?
** edit **
please! there 2 statements question marks... questions!
now, let me add may not mislead answers...
- i know
element.style
available across browsers. - i know
element.style.width
available. - using jquery 1.3.2, calling
$("#container .foo").css('width')
return"75%"
which not true since @ least version 1.6.4 (we're beyond major release too); recent jquery version output width in pixels now.
so, considering given html, getting element's style.width
return true, declared size (ie. in percentage) across browsers, or there rogue, non-standard 1 return computed width in pixels?
yes supported in major browsers. seem here notes old ie versions.
here can found available properties in version of dom
api.
edit
about consistence of value returned across browsers... that's depends on you, since returns only what's attributed via api: if use %
, you'll %
; if use em
you'll em
, on.
it couldn't make sense other way. let's apply 70% width in element and, hypothetically, engine uses pixel values under hood. convert value internally 70% of pixels count of parent's width. once parent's width changed value stored in pixels gone forever, evaluated in percentage value.
tl;dr - makes sense stored is, give get.
i'm pretty sure behavior. make sure, confirmed behavior on earlier versions of chrome, firefox, opera , ie 8+. so, remain in peace buddy , enjoy feature.
Comments
Post a Comment