Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get all supported CSS properties in WebKit?

In Firefox, Opera and IE I can get them via:

>> for (k in document.body.style) console.log(k)
-> opacity
   background
   height
   textAlign
   .
   ... long list ...
   .
   pointerEvents

In WebKit the result is quite different:

>> for (k in document.body.style) console.log(k)
-> cssText
   length
   parentRule
   getPropertyValue
   getPropertyCSSValue
   removeProperty
   getPropertyPriority
   setProperty
   item
   getPropertyShorthand
   isPropertyImplicit

Update: latest WebKit does enumerate over CSS properties in HTMLElement.style same way all the over browsers do.

like image 397
NVI Avatar asked Apr 10 '10 21:04

NVI


2 Answers

The answer is

>> document.defaultView.getComputedStyle(document.body, '')
-> CSSStyleDeclaration
   0: "background-attachment"
   1: "background-clip"
   2: "background-color"
   3: "background-image"
   4: "background-origin"
   5: "background-position"
   6: "background-repeat"
   7: "background-size"
   8: "border-bottom-color"
   9: "border-bottom-left-radius"
   ...

Thanks to Anton Byrna for his solution.


One problem still remains: getComputedStyle() does not return shortcuts like background and border.

like image 105
NVI Avatar answered Sep 26 '22 13:09

NVI


I'm not sure about the Javascript access, but you may look up all supported properties (even the proprietaries) here: CSS property names.

like image 26
fuxia Avatar answered Sep 23 '22 13:09

fuxia