jQuery - how to check if two elements are the same?

前端 未结 4 559
感情败类
感情败类 2020-12-16 09:59

I need to pass an element to a function and then match that specific element while traversing parent. The catch (for someone clueless like me) is that this element doesn\'t

4条回答
  •  一整个雨季
    2020-12-16 10:03

    Comparing JQuery objects will never return true, because each JQuery object is a a new object, even if their selectors are equal.

    To compare elements, you have to check whether the DOM elements are equal:

    this === element.get(0);
    

提交回复
热议问题