W3cubDocs

/Web APIs

MediaQueryListEvent: MediaQueryListEvent() constructor

The MediaQueryListEvent() constructor creates a new MediaQueryListEvent object.

Syntax

js

new MediaQueryListEvent(type)
new MediaQueryListEvent(type, options)

Parameters

type

A string with the name of the event. It is case-sensitive and browsers always set it to change.

options Optional

An object that, in addition of the properties defined in Event(), can have the following properties:

media Optional

A string representing a serialized media query. It defaults to "".

matches Optional

A boolean value representing the media query status; true if it matches, false if not. It defaults to false.

Return value

A new MediaQueryListEvent object.

Examples

js

const media = "(max-width: 600px)";
const matches = true;

const myMediaQueryListEvent = new MediaQueryListEvent("change", {
  media,
  matches,
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
MediaQueryListEvent 39 79 55 No 26 14 39 39 55 26 14 4.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryListEvent/MediaQueryListEvent