alex alex - 3 years ago 164
HTML Question

How to select the first character of the next word in a textarea?

Right now, I'm selecteing the first character (a) of the first word inside the text area like this:

<textarea ref="inputEl">abc def ghi</textarea>

methods: {
setInitialCursorPosition () {
const inputEl = this.$refs.inputEl
inputEl.setSelectionRange(0, 1)

mounted () {
this.$nextTick(() => {

How to do it so I select the first character of the next word inside the same text area (d and so on)? Pretty much like the
key in the Vim editor.

Answer Source

var str     = document.getElementById("textarea").value;
var match = str.match(/\b(\w)/g);              
var first = match.join('');  

<textarea id="textarea" ref="inputEl">abc def ghi</textarea>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download