DOMTokenList.remove()

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

语法

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

参数列表

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

返回值

undefined

示例

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

HTML:

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

JavaScript:

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

输出如下:

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

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

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

描述

Specification Status Comment
DOM
remove()
Living Standard Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
removeChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support 10Opera Full support YesSafari Full support 5.1WebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support 5.1Samsung Internet Android Full support Yes

Legend

Full support  
Full support