matchMedia method
Accepts a string containing one or more media queries, and returns a MediaQueryList object.
![]() |
Syntax
var retVal = Window.matchMedia(mediaQuery);Parameters
- mediaQuery [in]
-
Type: DOMString
- retVal [out, retval]
-
Type: MediaQueryList
Standards information
- CSSOM View Module, Section 4
Remarks
The following example creates a media query that checks whether the width or height of a window is less than a certain size.
Examples
mql = window.matchMedia("(min-height:250px)");
mql.addListener(sizeChange);
function sizeChange(mql) {
v = document.getElementById("myDiv");
if (mql.matches) {
v.innerHTML = "getting big" + "<br/>" + mql.media;
} else {
v.innerHTML = "getting small" + "<br/>"+ mql.media;
}
}
See also
Show:
