JavaScript Window method: matchMedia()
[this page | pdf | back links]
The matchMedia() method (when applied to Window
objects in the JavaScript
BOM) returns a
MediaQueryList object representing the results of applying a specified CSS media
query string.
It
has the following syntax with the following parameters. It returns a MediaQueryList
object.
window.matchMedia(mediaquerystring)
Parameter
|
Required / Optional
|
Description
|
mediaquerystring
|
Required
|
String representing
media query. This can be any media features that can be included in a CSS @media rule
|
A MediaQueryList object
has two properties and two methods:
Properties:
Property
|
Description
|
More
|
matches
|
Returns true if document matches the
specified media query list, false
otherwise
|
|
media
|
Returns a string
representing the serialised media query list
|
|
Methods:
Method
|
Description
|
More
|
addEventListener()
|
Adds new listener
function, evaluated whenever media query’s evaluated result changes
|
|
removeListener()
|
Removes previously
added listener function (or does nothing if listener function was not present
|
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)