Skip to content

getComputedStyle in V4 doesn't contain variables #16612

Answered by wongjn
quentinjeanningros asked this question in Help
Discussion options

You must be logged in to vote

You'd want to call the getComputedStyle() with the element that matches :root, i.e. <html>:

const cleanVariableName = variableName.replace(/^var\((.*)\)$/, '$1');

-const styles = getComputedStyle(document.body);
+const styles = getComputedStyle(document.documentElement);
 const value = styles.getPropertyValue(cleanVariableName).trim();

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@quentinjeanningros
Comment options

@quentinjeanningros
Comment options

Answer selected by quentinjeanningros
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants