how to compare two elements in jquery [duplicate]

var a=$('#start > div:last-child');
var b=$('#start > div.live')[0];
alert(a==b)
alert(a==$(b))

It's always false. How can you compare two elements in jQuery?

thanks


Solution 1:

For the record, jQuery has an is() function for this:

a.is(b)

Note that a is already a jQuery instance.

Solution 2:

You could compare DOM elements. Remember that jQuery selectors return arrays which will never be equal in the sense of reference equality.

Assuming:

<div id="a" class="a"></div>

this:

$('div.a')[0] == $('div#a')[0]

returns true.