Make sure the two elements are siblings in JS / jQuery
2 answers
I am not 100% sure why this does not work, but I believe that this is because the elements are wrapped in jQuery objects that are essentially different from each other.
As a workaround, you can compare your own DOM object, for example:
($('#a').parent()[0] == $('#b').parent()[0]); // true
+6
For the same reason that $('#a) == $('#a')there isfalse
, jQuery , ( jQuery , ). JavaScript, , , ;
var a = {
foo: 1
};
var b = {
foo: 1
};
(a == b) // false;
, DOM ( .get(i), jQuery, ([i])), is();
if ($('.foo').get(i) == $('.bar').get(i));
if ($('.foo')[0] == $('.bar')[0]);
if ($('.foo').is($('.bar')); // or even...
if ($('.foo').is('.bar'));
+3