> From: Adrian Lynch > > Am I right in thinking that you can't test for equality of > jQuery objects? > > alert($("#saveForm") == $("#saveForm")); // false > alert($("#saveForm") === $("#saveForm")); // false > alert($("#saveForm").get(0) == $("#saveForm").get(0)); // true > alert($("#saveForm").get(0) === $("#saveForm").get(0)); // true > > Instead I have to drop out of jQuery and test the elements directly. > > Am I missing something maybe?
You're right. They are two separate objects, and two objects never compare identically. It's no different from this: var obj = {}, a1 = [obj], a2 = [obj]; Now a1 !== a2, but a1[0] === a2[0]. But the real question is why do you want to do that? Instead of calling $('#saveForm') repeatedly, call it once and save the jQuery object. var $saveForm = $('#saveForm'); Now use $saveForm everywhere that you would have used $('#saveForm'). -Mike