JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="text"><a href="/" id="link">Click here</a></textarea>

<a href="#" id="add_attr">Add attribute</a>
<a href="#" id="remove_attr">Remove attribute</a>

CSS

textarea {
    width:200px;
    height:200px;
}

JavaScript

$(document).ready(function()
{
    $('#add_attr').click(function()
    {
        var value = '<div>' + $('#text').val() + '</div>';
        _value = $(value);
        _value.find('a').addClass('name');
        _value = _value.contents();
        $('#text').val($('<div>').append(_value.clone()).remove().html());
        return false;
    });

    $('#remove_attr').click(function()
    {
        var value = '<div>' + $('#text').val() + '</div>';
        _value = $(value);
        _value.find('a').removeClass('name');
        _value = _value.contents();
        $('#text').val($('<div>').append(_value.clone()).remove().html());
        return false;
    });
 });