3

In css I have this

@media screen and (max-width: 860px) { } 

what would be the equivalent javascript code to get the same width value that the css uses for @media max-width?

Thanks

4
  • should just be window.innerWidth Commented Nov 19, 2018 at 21:16
  • @dotconnor Actually innerWidth Commented Nov 19, 2018 at 21:19
  • do you want to get/set this css property max-width: 860px from your js ? Commented Nov 19, 2018 at 21:24
  • no, just find out what the JS width code is that the css uses for that Commented Nov 19, 2018 at 21:24

1 Answer 1

4

I believe that there is no way to get CSS from JavaScript code without parsing CSS file. JavaScript has a similar method is matchMedia. Usage:

if (window.matchMedia("(min-width: 400px)").matches) { /* the viewport is at least 400 pixels wide */ } else { /* the viewport is less than 400 pixels wide */ } 
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.