I have an HTML document with a link tag in its head to a particular CSS stylesheet:
<link rel="stylesheet" href="style.css" type="text/css">
This .css
file contains a particular class, like so:
.mystyle {
color: #00c;
}
What I'm trying to do is to grab that class's color
field, so that I can use it dynamically in another part of the page (for another element's background-color
). Is there any way in a JavaScript program to access that information, by the name of the class? Something like this:
var myColor = document.getStyle(".mystyle").color;
Some caveats:
- There may or may not be other stylesheets that are also linked from this HTML document.
- There may or may not be any particular elements on the page that are styled with this particular class.
- I've already tried setting a temporary element to have the given class, and then grabbing its
color
field. That didn't work: thecolor
field contains the empty string.
Thanks.