Reputation: 491
Reading about jQuery objects from here, it states that all jQuery objects are unique, even if they that "This is true even if the object was created with the same selector or contain references to the exact same DOM elements."
So for example, the following would equate to false
:
$( "#logo" ) === $( "#logo" )
Why are jQuery objects all unique?
Thanks
Upvotes: 6
Views: 103
Reputation: 8728
Try following:
$( "#logo" ).get(0) === $( "#logo" ).get(0)
As far as I know this compares the original Javascript-DOM-Object like you get with e.g.
document.getElementById( "logo" ) === document.getElementById( "logo" )
Upvotes: 1
Reputation: 136114
Because, essentially, jQuery is using the factory pattern which creates a new instance of a jQuery object from a selector each time you call it.
As these are different instances, they are not equal.
Upvotes: 8