MediaList - Web APIs 编辑

The MediaList interface represents the media queries of a stylesheet, e.g. those set using a <link> element's media attribute.

Note: MediaList is a live list; updating the list using properties or methods listed below will immediately update the behavior of the document.

Properties

MediaList.mediaText
A stringifier that returns a DOMString representing the MediaList as text, and also allows you to set a new MediaList.
MediaList.length Read only
Returns the number of media queries in the MediaList.

Methods

MediaList.appendMedium()
Adds a media query to the MediaList.
MediaList.deleteMedium()
Removes a media query from the MediaList.
MediaList.item()
A getter that returns a CSSOMString representing a media query as text, given the media query's index value inside the MediaList.

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

SpecificationStatusComment
CSS Object Model (CSSOM)
The definition of 'MediaList' in that specification.
Working Draft

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:124 次

字数:3406

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文