Skip to main content
Home / Code Snippets / jQuery Code Snippets / Compare jQuery Objects

Compare jQuery Objects

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