After calling window.getComputedStyle, how can I tell whether a style a style is from the page itself (rather than being from the browser)? I’m interested in doing so in pure javascript, though I would settle for a solution which ran in the context of an add-on.
After calling window.getComputedStyle , how can I tell whether a style a style is
Share
You will have a hard time figuring out where the rules that
getComputedStylegives you came from. Note that the code provided by MaxArt isn’t a complete solution – there are also inherited styles so one would have to repeat everything for parent nodes. The simpler approach would be usinginIDOMUtils.getCSSStyleRules(), along these lines:You will have to do it for the parent nodes as well. For a complete example you can look at the implementation of the Inspector feature in Firefox (
isPageStylefunction in my answer shamelessly “borrowed” from here).