You can’t really compare if two jQuery objects are the same…
if ($(selectionOne) === $(selectionTwo)) {
}
You can compare DOM objects though…
if ($(selectionOne)[0] === $(selectionTwo)[0]) {
}
But that’s only really useful if you’re comparing a single element, not a collection.
If you need to compare a collection of elements, this StackOverflow thread has the answer:
var divs = $("div");
var divs2 = $("div");
if (divs.length == divs2.length && divs.length == divs.filter(divs2).length) {
// They are equal
}
I think the
is
method would work in some of those cases too.not true. Is returns true if at least a single item matches.
is == Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments.
http://api.jquery.com/is/
(Just kidding.)