I've seen a few questions like this but can't find a solution. I have a textbox. When the user is typing along, if they press @
, I'd like to show a list of items they can select from, at that caret's position (i.e. the place in the textbox where the next character typed will appear, not the location of the mouse cursor).
JSfiddle: http://jsfiddle.net/LR8pe/
Code:
$(".textarea").bind("keypress", function (e) {
if (String.fromCharCode(e.keyCode) == '@') {
$(".list").show();
} else{
$(".list").hide();
}
});
I have the basic mechanics down, but showing/hiding at the position of the caret is where I'm stuck.
I'm using jquery/knockout, but pure JS is fine with me.