W3C home > Mailing lists > Public > www-style@w3.org > March 2009

Re: setting css property to empty string from script

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Fri, 6 Mar 2009 14:11:12 -0800
Message-ID: <c9e12660903061411p1c9ab225tec4a049a27c93a42@mail.gmail.com>
To: Mike Wilson <mikewse@hotmail.com>
Cc: www-style <www-style@w3.org>
On Fri, Mar 6, 2009 at 8:50 AM, Mike Wilson <mikewse@hotmail.com> wrote:
> When you have overrided the value of an element's CSS attribute
> through script, then you can reset the attribute back to the
> value governed by style declarations by assigning the empty
> string. Example (see *):
>
>  <style type='text/css'>
>    span {border: 1px solid red}
>  </style>
>  <span id=myspan>lorem ipsum</span>
>
>  e = document.getElementById("myspan");
>  window.getComputedStyle(e,"").borderLeftWidth
>  -> "1px"
>

Nonstandard. Some implementations may treat window as a reference to
document.defaultView, but window is not guaranteed to be
document.defaultView.

Try it in Safari 2, for example.

>  e.style.borderLeftWidth = 2;
>  window.getComputedStyle(e,"").borderLeftWidth
>  -> "2px"
>

Nonstandard. Use a unit. Use a string value. Dom setters that are
standardized to take domstring should take a domstring. Assigning a
number is nonstandard and does not work consistently.

Garrett
Received on Friday, 6 March 2009 22:11:48 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:17 GMT