1

I have defined a style sheet using Cascading Variables.

:root {
        --media: narrow;
}

@media all and (min-width: 30rem)
{
        :root {
                --media: wide;
        }
}

Firefox understands this and shows me the property in the Inspector.

But how to read it from JavaScript?

I tried it with jQuery 2.1.3 but it does not seem to work:

$('html').css('--media')
undefined
$('html').css('media')
undefined
$(':root').css('media')
undefined

Which native function I have to use?

2

1 Answer 1

1

Thanks Rakesh!

I got it:

window.getComputedStyle(document.body, ':root')
      .getPropertyValue('--media')
      .trim()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.