DOMTokenList.remove()

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.

remove() 方法从 DOMTokenList 中移除指定标记。

语法

tokenList.remove(token1[, token2[, ...]]);

参数列表

tokenN...

表示要从列表中移除的一个 DOMString。如果列表中不存在该字符串,不会出错也没有任何变化。

返回值

undefined

示例

在下面的示例中,我们使用 Element.classList 检索 <span> 元素上设置的 class 列表作为 DOMTokenList。然后从列表中删除一个标记,并将该列表写入<span>Node.textContent 中。

HTML

html
<span class="a b c"></span>

JavaScript

js
var span = document.querySelector("span");
var classes = span.classList;
classes.remove("c");
span.textContent = classes;

输出如下:

要一次删除多个 class,可以提供多个标记。书写顺序不必与它们在列表中出现的顺序匹配:

js
let span = document.getElementsByTagName("span")[0],
  classes = span.classList;

classes.remove("c", "b");
span.textContent = classes;

描述

Specification
DOM
# ref-for-dom-domtokenlist-remove①

浏览器兼容性

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
remove
Multiple parameters for remove()

Legend

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

Full support
Full support