I have a autocomplete search field (typeahead.js) and I have a behaviour triggered when clicking on a search suggestion ie on click
.
I would like the same behaviour triggered when arrowing down and pressing enter on a suggestion.
So I would like the behaviour to occur on click
or on pressing enter
.
In the example below, I use an input field rather than replicating the full typeahead.js search scenario.
The problem with the code below is that it is only triggered when pressing enter in the input field (because of the conditional attached to e
) and not on click
.
HTML
<input class="hello" value="hello">
jQuery
$(document).on("click keypress",".hello", function (e) {
if (e.which == 13) {
alert($(this).val());
}
});
jsFiddle
http://jsfiddle.net/rwone/9xhK3/
Edit:
Updated jsFiddle with typeahead code: