html textarea along with cursor position set

Solutions on MaxInterview for html textarea along with cursor position set by the best coders in the world

showing results for - "html textarea along with cursor position set"
Damián
27 Jan 2020
1document.getElementById('bold').addEventListener('click', boldText);
2
3function boldText() {
4  var txtarea = document.getElementById("editor_area");
5  var start = txtarea.selectionStart;
6  var end = txtarea.selectionEnd;
7  var sel = txtarea.value.substring(start, end);
8  var finText = txtarea.value.substring(0, start) + '[b]' + sel + '[/b]' + txtarea.value.substring(end);
9  txtarea.value = finText;
10  txtarea.focus();
11  txtarea.selectionEnd= end + 7;
12}