0

According to the jQuery documentation, "Not All jQuery Objects are Created ===."

"An important detail regarding this "wrapping" behavior is that each wrapped object is unique. This is true even if the object was created with the same selector or contain references to the exact same DOM elements."

documentation

I know how to work around this but why is this the case? Is this some specific way that JavaScript behaves?

1 Answer 1

4

Yes. Every object in JS is unique, in that o1 === o2 will not be true unless o1 and o2 are pointers to the same object.

{ foo: 1 } === { foo: 1 }; // false

So jQuery objects simply follow this same rule:

var jq1 = $('.foo');
var jq2 = $('.foo');
jq1 === jq2; // false

The only exception is if you have variables that actually point to the same jQuery object:

var jq3 = jq1;
jq3 === jq1; // true
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.