I need to compare if different selectors returns same matched set of elements.
I came to this easy solution, a little plugin:
;(function ($) {
$.fn.isEqual = function ($selector) {
return this.add().get().join() === $selector.add().get().join()
}
})(jQuery);
//e.g of usages: if($('div').isEqual($('#mydiv1,#mydiv2'))
//if($(':checkbox').isEqual($('input[type=checkbox].myclass'))
//if($('div').parents().isEqual($('body div').parents()) etc ...
Now i think i'm missing something as all other solutions i have find seems really more elaborate, like this one which seems to be the privileged one:
$.fn.sequenceEqual = function(compareTo) {
if (!compareTo || !compareTo.length || this.length !== compareTo.length) {
return false;
}
for (var i = 0, length = this.length; i < length; i++) {
if (this[i] !== compareTo[i])
return false;
}
}
return true;
}
So, what can be the downside of using $.isEqual plugin?