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}