Test if two elements are the same

前端 未结 7 1450
予麋鹿
予麋鹿 2020-12-07 21:32

I would suspect this to work at first:

if ($(\'#element\') == $(\'#element\')) alert(\'hello\');

But it does not. How does one test if ele

相关标签:
7条回答
  • 2020-12-07 22:33

    9 years later, without jQuery

    If two elements are the same one, two elements must have the same pointer. Thus,

    document.body === document.body // true
    document.querySelector('div') === document.querySelector('div') // true
    document.createElement('div') === document.createElement('div') // false
    
    0 讨论(0)
提交回复
热议问题