Josef Pfleger
Josef Pfleger

Reputation: 74507

Mapping computed CSS styles to specified ones?

Is there a way to map the computed style of a dom element (as retrieved by window.getComputedStyle) to a corresponding CSSStyleRule in document.styleSheets?

My ultimate goal is to retrieve specified values for dom elements (rather than computed values or actual values).

Upvotes: 0

Views: 442

Answers (1)

Ionuț G. Stan
Ionuț G. Stan

Reputation: 179098

As far as I know, only IE (with element.currentStyle) allows JS to retrieve the specified values, which is a good thing in my opinion. All the other browsers return the computed values.

I once needed the specified value and the only thing that crossed my mind was to make a CSS parser that would map an element to a rule based on the element's xpath. It would have been some kind of a reversed jQuery, where you would supply a DOM element and it would have returned the CSS rules associated with it after parsing all the loaded CSS. Unfortunately I didn't have the time to start the project.

Upvotes: 2

Related Questions