Finding Inactive CSS Properties
Is it possible to define styles in a CSS file via Javascript?
I am trying to detect CSS properties that will be applied to an element in a specific state, :hover
in this case, but without those properties currently active on the element. I thought about cloning the element, adding the clone as sibling with display: none
and requesting the properties that way, but I don't know how to get the style to :hover
use Javascript. Any ideas?
source to share
I believe you are interested in an array styleSheets
, which is a property of document
( document.styleSheets
). This array indexes all of the style sheets referenced by the current page and allows you to iterate over all the style rules on each sheet. The W3C (Firefox, Opera, Safari) array for accessing CSS rules is cssRules
, whereas the Microsoft rules
. The following code snippet is taken from www.quirksmode.org :
var theRules = new Array();
if (document.styleSheets[1].cssRules)
theRules = document.styleSheets1.cssRules
else if (document.styleSheets[1].rules)
theRules = document.styleSheets1.rules
Now theRules
contains the rules for the second style sheet for the document. See the Quirksmode link and compatibility tables for more information on accessing CSS rules from JavaScript.
source to share