You are comparing two distinct jQuery objects because you call $()
twice (once for each side of the equation), and as MooGoo explains jQuery creates new wrapper objects for each time you call it. That's why the comparison ends up returning false.
You can extract a DOM object from each jQuery object by either using get()
or array dereferencing, then compare these elements. The following both return true because both identical selectors match the same body
DOM element:
$('body').get(0) == $('body').get(0)
$('body')[0] == $('body')[0]
If you want to test against a jQuery selector, use is()
. Note that, unless your selectors are identical, the selectors you use may not necessarily match the same DOM elements (it's still better to use the above). This also returns true:
$('body').is('body')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…