get text under current cursor positon inside a textarea

is there a way to get a string under current cursor position inside a textarea
for example – click on lorem – console should be lorem
essentially, something like this:

  let a = previous space or line break from cursor position
  let b = next space or line break from cursor position
  console.log(text from a to b);
$('#ed').on('click', function(){
  //let a = previous space or line break from cursor position
  //let b = next space or line break from cursor position
  //console.log(text from a to b);
});
#ed{
display:block;
width:100%;
padding:9px;
height:50vh;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea id='ed'>
lorem ipsum
https://google.com
</textarea>

13 thoughts on “get text under current cursor positon inside a textarea”

  1. 340070 226775As I internet site possessor I believe the content material here is genuinely excellent , regards for your efforts. 283539

    Reply
  2. 774689 27115Wow! This could be one particular with the most helpful blogs Weve ever arrive across on this subject. In fact Excellent. Im also an expert in this topic therefore I can recognize your hard work. 733205

    Reply

Leave a Comment