I would like to get the word after @depending on the current position of the record textarea. More precisely:
if the current cursor position is on any letter @<user>, the answer should be<user>
if the current cursor position is on any other word, the answer should be empty ''
I struggle with this, but I don’t find a “good” 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 me this is a long text, here is another @username cheers!</textarea>
<span id="hey">CLICK ME</span>
Run codeHide result
source
share