Detect ":" and show suggestions with jQuery

2

I have a textarea and I would like to know how to detect the : character and from there, show suggestions listed in an array with all the possibilities of "auto complete" and filter the results ...

Here is an example:

I already thought of detecting the : character from keydown using event keyCode but I do not know how I would do it since in Windows I would have to detect shift + : and on Mac I no longer know if it's the same thing. I also thought about only detecting the : character from val() of textarea but I do not know how I could proceed.

What is the correct way to do this? And how to do it?

Preferably, I would really like to learn how to do only with jQuery and without the use of libraries.

Thanks!

    
asked by anonymous 25.04.2015 / 01:15

1 answer

2

There are a few libraries out there to do autocomplete within a textarea. Have you considered using one? For example: link

If I'm not mistaken, most of them detect the position of the cursor within the textarea instead of looking at the keycode. One advantage of this is that you can filter the dropdown as you type. The bad news is that browsers do not have a consistent API to pick up the cursor position.

    
25.04.2015 / 01:57