I am a newbie on jQuery and was building an auto-suggest box for my website. I used the following HTML:
<input type="text" name="suggest" class="autosuggest1">
<div class="dropdown">
<ul class="result1">
</ul>
</div>
I have added elements to ul list on the go by the following jQuery code:-
$(document).ready(function () {
$('.autosuggest1').keyup(function () {
var search_term = $(this).val();
$.post("search.php", {
search_term: search_term
}, function (data) {
$('.result1').html(data);
$('.result1 li').click(function () {
var result = $(this).text();
$('.autosuggest1').val(result);
$('.result1').html('');
});
});
});
});
My problem is that the element is selected only by clicking it and I want it to get also selected by arrow keys on keyboard. I can't figure how.