Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about parens in matchMedia #37504

Merged
merged 11 commits into from
Jan 23, 2025
2 changes: 2 additions & 0 deletions files/en-us/web/api/window/matchmedia/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ matchMedia(mediaQueryString)
- `mediaQueryString`
- : A string specifying the media query to parse into a {{domxref("MediaQueryList")}}.
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved

Just like in CSS, any [media feature](/en-US/docs/Web/CSS/@media#media_features) must be wrapped in parentheses inside the expression. For example: `matchMedia('(max-width: 600px)')` will work, whereas `matchMedia('max-width: 600px')` will not. Keywords for media types (`all`, `print`, `screen`) and logical operators (`and`, `or`, `not`, `only`) do not need to be wrapped in parentheses.
Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved

### Return value

A new {{domxref("MediaQueryList")}} object for the media query. Use this object's
Expand Down
Loading