How can I test if two jQuery wrapped DOM elements are the same? [duplicate] How can I test if two jQuery wrapped DOM elements are the same? [duplicate] jquery jquery

How can I test if two jQuery wrapped DOM elements are the same? [duplicate]


A jQuery object can be treated as an array of raw DOM elements.

You can compare the raw DOM elements like this:

if(ele2[0] === ele3[0])


Compare the DOM elements inside like this:

if (ele1.get(0) == ele2.get(0))


This is also a possible way to solve this problem. You can compare the id attributes since they should be the exact same in your example above.

ele1.attr("id") == ele2.attr("id"); //returns falseele2.attr("id") == ele3.attr("id"); //returns true