将DOM节点与DOM元素进行比较 [英] Comparing a DOM Node wih a DOM Element
本文介绍了将DOM节点与DOM元素进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
只需执行 ===
比较。因为它们都是对象,所以比较将是基于身份的。
if(my_node === my_element){
//他们是一样的东西
}
I'm having some trouble figuring this problem out. I'm aware that everything in a DOM is a node and that a DOM element is also a node. However, my problem is this: I have a DOM node and a DOM element and I need to compare these to see if they are referring to the same element. Is that even possible? I think there is something fundamentally wrong with my question but can't figure out what it is. Thanks for your help.
解决方案
Just do an ===
comparison. Since they're both objects, the comparison will be identity based.
if (my_node === my_element) {
// they're the same thing
}
这篇关于将DOM节点与DOM元素进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文