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

Re: Proposal: getStyleAs(property, primitiveValue)

From: Michael A. Puls II <shadow2531@gmail.com>
Date: Wed, 23 Sep 2009 18:31:23 -0400
To: "Garrett Smith" <dhtmlkitchen@gmail.com>, √ėyvind Stenhaug <oyvinds@opera.com>
Cc: www-style <www-style@w3.org>
Message-ID: <op.u0qd6jzn1ejg13@sandra-svwliu01>
On Wed, 23 Sep 2009 17:02:54 -0400, Garrett Smith <dhtmlkitchen@gmail.com>  
wrote:

> document.defaultView.getComputedStyle is too verbose and clunky and
> getComputedStyle is shorter and simpler.

The document.defaultView.getComputedStyle way can be used for stuff like  
this:

Element.prototype.getComputedStyle = function(property) {
     return this.ownerDocument.defaultView.getComputedStyle(this,  
null).getPropertyValue(property);
};
// or even
Element.prototype.getStyle = Element.prototype.getComputedStyle;

window.onload = function() {
     alert(document.body.getComputedStyle("width"));
     alert(document.body.getStyle("width"));
};

, where this.ownerDocument.defaultView.getComputedStyle feels more correct  
than just getComputedStyle(), even if the latter works.

-- 
Michael
Received on Wednesday, 23 September 2009 22:32:12 GMT

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