comparing jQuery objects
Following on from bobince, instead of using wrapper[0] use the proper get(0) method to return the first element stored in your jQuery object.
var focused = null;
$(':input').focus( function() {
focused = $(this);
compare($(this));
//Compare them...trivial but will return true despite being different jQuery objects.
}).blur( function() {
focused = null;
});
function compare(element) {
if (element.get(0) === focused.get(0)) {
alert('The same');
}
}
You can't make the comparison on the jQuery wrapper, but you can make it on the underlying DOM Node. Lose a few dollars and you're fine:
.focus(function(){
var that= this;
$openMenus.each(function(){
if (this!==that){
[do something]
}
});
})
(or use eg. wrapper[0]
to get the DOM Node from a single-item jQuery wrapper.)
(I used ===
for the comparison because it's usually best, but it would work with ==
too in this case.)