MediaQueryListEvent: MediaQueryListEvent() constructor
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The MediaQueryListEvent()
constructor creates a new MediaQueryListEvent
object.
Syntax
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 tofalse
.
Return value
A new MediaQueryListEvent
object.
Examples
const media = "(max-width: 600px)";
const matches = true;
const myMediaQueryListEvent = new MediaQueryListEvent("change", {
media,
matches,
});
Specifications
Specification |
---|
CSSOM View Module # dom-mediaquerylistevent-mediaquerylistevent |
Browser compatibility
BCD tables only load in the browser