KK123
KK123

Reputation: 217

Accessing external css property in javascript code

In my javascript code, i am trying to access a child's class which is present in external style sheet. Using

window.getComputedStyle("className", null).getPropertyValue("color") 

throws an Unhandled error: WRONG_ARGUMENTS_ERR. Do anyone see any issue in this? I want to access the class property, which is present in external stylesheet.

Thanks

Upvotes: 3

Views: 204

Answers (1)

gherkins
gherkins

Reputation: 14983

i think you'll need to feed getComputedStyle() a DOM-Element, not just the ClassName

maybe try:

var el = document.getElementsByClassName("className")[0];

window.getComputedStyle(el, null).getPropertyValue("color");

Upvotes: 2

Related Questions