web api interface
MediaList
The MediaList interface represents the media queries of a stylesheet, e.g., those set using a <link> element’s media attribute.
[!NOTE]
MediaListis a live list; updating the list using properties or methods listed below will immediately update the behavior of the document.
Instance properties
mediaText- : A stringifier that returns a string representing the
MediaListas text, and also allows you to set a newMediaList.
- : A stringifier that returns a string representing the
lengthRead only- : Returns the number of media queries in the
MediaList.
- : Returns the number of media queries in the
Instance methods
appendMedium()- : Adds a media query to the
MediaList.
- : Adds a media query to the
deleteMedium()- : Removes a media query from the
MediaList.
- : Removes a media query from the
item()- : A getter that returns a string representing a media query as text, given the media query’s index value inside the
MediaList. This method can also be called using the bracket ([]) syntax.
- : A getter that returns a string representing a media query as text, given the media query’s index value inside the
toString()- : Returns a string representation of this media list in the same format as the object’s
mediaTextproperty.
- : Returns a string representation of this media list in the same format as the object’s
Examples
The following would log to the console a textual representation of the MediaList of the first stylesheet applied to the current document.
const stylesheets = document.styleSheets;
let stylesheet = stylesheets[0];
console.log(stylesheet.media.mediaText);
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.