views:

1932

answers:

2
+2  A: 

Is it possible to get only the stylesheet specified styles of an element (and return null if the style is undefined)?

That's effectively what is done by the routine you present. The problem is, in most scenarios, most styles are not undefined - they're inherited and/or defined by the individual browser's internal stylesheet.

You could, with a whole lot of effort, iterate through all of the rules defining the style in question, in all of the stylesheets in the current view of the document, evaluate them for the element in question, and if none applied... and if none applied to a parent (or this particular style is not inherited)... then consider it undefined. This would be slow, and incredibly error-prone. I would not recommend trying it.

Perhaps you would do better to step back and ask why you would ever need such a thing?

Shog9
Thanks for the well thought out answer Shog - I ended up combining Pez's idea with your suggestion try thinking about it a different way!
jb
+2  A: 

Maybe your component can wrap the styles that it controls? Then when a style is set through the component the component knows what the user wants.

PEZ
Idea light bulb!
jb