If I try something such as this:
$(".foo") === $(".foo") // = false
… I get false. If I instead try this query,
$(".foo").get(0) === $(".foo").get(0) // = true
… I get true.
That’s because:
{a:myObject} !== {a:myObject};
[myObject] !== [myObject];
myObject === myObject;
I’m wondering if there is any succinct way to test for this equality, preferably built into jQuery. The 2nd method I wrote only works correctly if there is at most one element which matches .foo. The solution should work for any amount of elements.
Obviously I don’t want to just check ".foo" === ".foo" since the actual selections I’m using are more complicated. I just simplified them for this example. (E.g. I may want to check that $(this) is selecting the same thing as $(".foo").)
There is nothing in the core library to check sequence equality of jQuery objects, however the following should do the trick:
Which would be useable like so:
For completeness, a contents equal method could be written like so:
Which would be useable like so: