HTMLLinkElement:media 属性

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.

HTMLLinkElement 接口的 media 属性是一个字符串,表示资源适用的一个或多个媒体格式的列表。

它反映 <link> 元素的 media 属性。

一个字符串。

示例

html
<link
  id="el"
  href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
  rel="stylesheet"
  media="screen and (min-width: 600px)"
  crossorigin="anonymous" />
js
const el = document.getElementById("el");
console.log(el.media); // 输出:“screen and (min-width: 600px)”

规范

Specification
HTML Standard
# dom-link-media

浏览器兼容性

BCD tables only load in the browser