gaurav gaurav - 6 months ago 24
jQuery Question

Get access to all css style properties?

I want to get access to all CSS properties (not only for a specific selector or element but all) through JavaScript.

I want to iterate through all properties of the

.style
collection.

How can i do this?

Answer

you can use CSSStyleDeclaration object. A CSSStyleDeclaration object makes CSS style attributes available through JavaScript properties. The names of these JavaScript properties correspond closely to the CSS attribute names.

this object has two additional properties:

cssText
The textual representation of a set of style attributes and their values. The text is formatted as in a CSS stylesheet, minus the element selector and the curly braces that surround the attributes and values.

length
The number of attribute/value pairs contained in this CSSStyleDeclaration. A CSSStyleDeclaration object is also an array-like object whose elements are the names of the CSS style attributes that are declared.

https://developer.mozilla.org/en/DOM/CSSStyleDeclaration
https://developer.mozilla.org/en/DOM/CSS

Comments