javascript - How to remove all event listeners from certain categories that are mentioned in Chrome Console in Event Listeners
问题描述
How do I remove all event listeners that are connected to the element that I can see in the Chrome Console in Event Listeners?
jQuery can be used if it will make it easier.
For example:
This is tab in Chrome console.
As you can see element is <a>
but it as also some listeners from <div>
, there is remove button next to each listener.
I would like to replicate something like this Remove button that deletes all listeners from mouseleave and mouseenter category.
I have tried to use jQuery's .unbind('mouseleave mouseover')
but it doesn't remove them.
Is there any way how can I access all listeners from one category and remove them?
解决方案
您可以将其替换为克隆:
const el = document.querySelector(...)
el.parentNode.replaceChild(el.cloneNode(true), el)
然后你可以重新连接你仍然需要的听过的东西(如果有的话)。
推荐阅读
- python - 使用 pandas 在 python 中重塑 CSV 数据
- java - 是否有任何最佳方法可以在 2 arrayList 中找到不同的值
- node.js - Node.js 和 Selenium Webdriver 安装问题
- javascript - 如何在自适应中折叠列表项的边界
- python - 是否有一种有效的算法来聚类大数据数组
- matlab - 将一组点的值表示为半径为 R 的圆
- html - 如何使按钮中的图标居中
- c# - 移植 C# 代码。这是对全局对象的引用吗?
- android - Android - 需要根据从 API 响应收到的 JSON 对象创建数据库
- javascript - 获取所有可能的数字组合(最快的方法)