How do I add and remove tags around selected text?

  • 0
    I want to process a string inside a textarea to get the selected text and add an element tag around it like
    	var el = $('.text_area')
    	var control = el[0];
    	var text = $(control).val();
    	if (control.selectionStart != control.selectionEnd) {
    		val = text.substring(control.selectionStart, control.selectionEnd);
    	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 habr
    JavaScript Anonymous, Nov 28, 2020

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!