How do I add and remove tags around selected text?
-
I want to process a string inside a textarea to get the selected text and add an element tag around it like
$('#click_but').click(function(){ var el = $('.text_area') var control = el[0]; var text = $(control).val(); if (control.selectionStart != control.selectionEnd) { val = text.substring(control.selectionStart, control.selectionEnd); console.log([el.val(),val]) } return false; });
Test text
It's just text.
[Dedicated test] Link [/ Dedicated test]
text is text
Текст для теста <br> Это просто текст <br> <a href="#">Ссылка</a> <br> текст есть текст <br>
and then return all the code as in habrJavaScript Anonymous, Nov 28, 2020
0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!