Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

html textarea along with cursor position set

document.getElementById('bold').addEventListener('click', boldText);

function boldText() {
  var txtarea = document.getElementById("editor_area");
  var start = txtarea.selectionStart;
  var end = txtarea.selectionEnd;
  var sel = txtarea.value.substring(start, end);
  var finText = txtarea.value.substring(0, start) + '[b]' + sel + '[/b]' + txtarea.value.substring(end);
  txtarea.value = finText;
  txtarea.focus();
  txtarea.selectionEnd= end + 7;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #html #textarea #cursor #position #set
ADD COMMENT
Topic
Name
5+6 =