Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

How to get selected text position from textarea in JavaScript?

$
0
0

I want to get the selected text position using javascript. For example,
I have a simple textarea.

#input-text {
  resize: none;
  width: 50%;
  height: 50px;
  margin: 1rem auto;
}
<textarea id="input-text">I am a student and I want to become a good person</textarea>

In my textarea, I have some text such as:

"I am a student and I want to become a good person"

From this string, if I select "become a good person" from the textarea,
Then How can I get the selected text/ string position in javascript?


Here the selected string character starts from 29 and ends in 49. So the start position is 29 & the end position is 49


Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>