Reputation: 3856
Here's what I have:
$(document).click(function(event) {
if ($(event.target) == $("a.nav-search")) {
console.log('search click');
}else{
console.log('no search click')
}
});
I'm trying to make it so if you click on a.nav-search do one thing, but if you click anywhere else, do another thing. When I try this, I just keep logging "no search click". I've console logged my event.target and I get this:
[a.nav-search, context: a.nav-search, constructor: function, init: function, selector: "", jquery: "1.7.1"…]
What am I doing wrong?
Upvotes: 0
Views: 38
Reputation: 33078
Answer
$(document).click(function(event) {
if ( $(event.target).is('a.nav-search') ) {
console.log('search click');
} else {
console.log('no search click')
}
});
Upvotes: 1