9951 explained code solutions for 126 technologies


javascriptInsert text into textarea at cursor position


var ta = document.querySelector('textarea');
ta.value = ta.value.substring(0, ta.selectionStart)
         + 'Some text'
         + ta.value.substring(ta.selectionEnd, ta.value.length);ctrl + c
document.querySelector('textarea')

query selector for required textarea element

'Some text'

this text will be inserted at current cursor position into textarea