0
<html>
<body>
<head>

<style type="text/css">
#someClass {
    color:red;
}
</style>

</head>

<div id="someClass"></div>

<script type="text/javascript">
alert(document.getElementById("someClass").style.color);
</script>

</body>
</html>

As you can see from my code I'm trying to figure out if I can reference a style attribute for a class that's defined in CSS, as opposed to directly in the tag's style attribute.

1 Answer 1

2

You're looking for window.getComputedStyle() - small usage example here.

   alert(window.getComputedStyle(document.getElementById('someClass')).color); 
#someClass {
    color:red;
}
<div id="someClass"></div>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.