Reputation: 19929
I have the following but it is not working. Does the jQuery event support the keyCode or do I need to get that someplace else?
$('#search-query').on('keyup',function(event){
if(event.keyCode!==38 or event.keyCode!==40){
search_autocomplete.call(this);
}
});
How would I tell jQuery to just ignore if it's keyCode 38 or 40? Ultimately, I want to get this to like the search bar on http://www.linkedin.com/. Maybe just bootstrap it? http://twitter.github.com/bootstrap/javascript.html#typeahead
thx in advance
Upvotes: 0
Views: 348
Reputation: 401
Have a look at keypress...
$('#search-query').keypress(function (e) {
if(e.which == 38 || e.which == 40)
search_autocomplete.call(this);
}
});
Not tested but hopefully this helps
Upvotes: 0
Reputation: 55740
Make sure you use both event.keyCode
and event.which
for cross browser compatibility
$('#search-query').on('keyup',function(event){
var key = event.keyCode || event.which;
if(key !==38 || key !==40){
search_autocomplete.call(this);
}
});
Upvotes: 2