MutationObserver.disconnect()
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.
MutationObserver
的 disconnect()
方法告诉观察者停止观察变动。可以通过调用其 observe()
方法来重用观察者。
语法
js
disconnect()
参数
无。
返回值
undefined
。
备注: 所有已经检测到但是尚未向观察者报告的变动都会被丢弃。
使用说明
如果被观察的元素被从 DOM 中移除,然后被浏览器的垃圾回收机制释放,此 MutationObserver
将同样被删除。
示例
下面的示例创建了一个观察者,接着与之断开连接,让它可以重复使用。
js
var targetNode = document.querySelector("#someElement");
var observerOptions = {
childList: true,
attributes: true,
};
var observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);
/* some time later... */
observer.disconnect();
规范
Specification |
---|
DOM # ref-for-dom-mutationobserver-disconnect① |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
disconnect |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.