r/javascript • • Aug 21 '18

Effectively supported in all browsers, JavaScript has its own form of media queries just like CSS.

https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
465 Upvotes

114 comments sorted by

View all comments

65

u/PortablePawnShop Aug 21 '18

Holy shit, I've been doing absurdly complicated workarounds for some of this

5

u/IIIIRadsIIII Aug 22 '18

What’s a good use case for this?

5

u/13steinj Aug 22 '18

Because of a "legacy" internal app I support that deals with lots of html tables that have complex "show/hide this column" rules in CSS, that.

Much easier to just have some JS conditionally fire or fire with a swutch than deal with many confusing media queries in the same CSS document. Depending on the implementation you also save in "time it takes for the dom to load because all the CSS has to be parsed and applied".

1

u/IIIIRadsIIII Aug 22 '18

Yesh. Yeah that makes sense there.