【发布时间】:2019-12-27 16:54:50
【问题描述】:
类似于 addEventListener("click"),但不是点击事件,而是我想更改 addEventListener("Is there abc DIV on page?")
document.addEventListener("Is there abc DIV on page?"){
If yes{
console.log("yes, there is abc div on page");
}
else{
console.log("no, there is no abc div on page");
}
}
//User can toggle the presence of abc div whenever they want
document.addEventListener("click/keyboard/...."){
Remove abc div or Add abc div;
}
每次用户切换 abc div 的存在时,此事件侦听器都会捕获并注意到更改。
谢谢
【问题讨论】:
-
MutationObserver 是您要找的吗?通常,它允许您在 DOM 更改时运行回调。
标签: javascript