It is, generally speaking, a bad idea to compare $(foo) with $(foo) as that is functionally equivalent to the following comparison:
<html>
<head>
<script language='javascript'>
function foo(bar) {
return ({ "object": bar });
}
$ = foo;
if ( $("a") == $("a") ) {
alert ("JS engine screw-up");
}
else {
alert ("Expected result");
}
</script>
</head>
</html>
Of course you would never expect "JS engine screw-up". I use "$" just to make it clear what jQuery is doing.
Whenever you call $("#foo") you are actually doing a jQuery("#foo") which returns a new object. So comparing them and expecting same object is not correct.
However what you CAN do may be is something like:
<html>
<head>
<script language='javascript'>
function foo(bar) {
return ({ "object": bar });
}
$ = foo;
if ( $("a").object == $("a").object ) {
alert ("Yep! Now it works");
}
else {
alert ("This should not happen");
}
</script>
</head>
</html>
So really you should perhaps compare the ID elements of the jQuery objects in your real program so something like
...
$(someIdSelector).attr("id") == $(someOtherIdSelector).attr("id")
is more appropriate.