I'd like to get the word after @
depending on the current writing position of a textarea
. More precisely:
if the current cursor position is on any letter of
@<user>
, the answer should be<user>
if the current cursor position is on any other word, the answer should be empty
''
I'm struggling with this, but don't find any "nice" way to do it.
$('#hey').on('click', function() { alert(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<textarea id="chat">hello @user it's me this is a long text, here is another @username cheers!</textarea>
<span id="hey">CLICK ME</span>