HTMLAnchorElement:relList 属性

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.

HTMLAnchorElement.relList 只读属性反映了 rel 属性。它是一个实时的 DOMTokenList,包含表示由 <a> 元素代表的资源与当前文档之间关系的链接类型。

该属性本身是只读的,意味着你不能将其替换为另一个 DOMTokenList,但其内容仍然可以被修改。

一个包含字符串的实时 DOMTokenList

示例

js
const anchors = document.getElementsByTagName("a");
for (const anchor of anchors) {
  const list = anchor.relList;
  console.log(
    `在 relList 中发现了包含 ${list.length} 个链接类型的新锚点节点。`,
  );
  list.forEach((relValue) => {
    console.log(relValue);
  });
}

规范

Specification
HTML
# dom-a-rellist

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
relList

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见