gpt4 book ai didi

javascript - 如何使用 MutationObserver 获取标签类型?

转载 作者:行者123 更新时间:2023-11-30 13:57:51 24 4
gpt4 key购买 nike

        let mObserver = new MutationObserver((mutationsList, observer) => {
mutationsList.forEach((mutation) => {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach((node) => {
console.log(node)
})
}
})
})

mObserver.observe(document.body, {
childList: true,
subtree: true
})

如何判断添加的 node 类型?我只想定位 a 标签

最佳答案

您可以使用 nodeName

if (node.nodeName.toLowerCase() === 'a') {
// Do things
}

关于javascript - 如何使用 MutationObserver 获取标签类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56876659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com