I am fetching the user input data from textarea on button click. If a user put some hyperlink code inside textarea, the function automatically recognize and add rel=nofollow. Now I need to assign these new hyperlink code inside textarea again and replace the old one.
I am able to add rel=nofollow and able to alert it
function naming() {
var rel_attribute = document.getElementById('textareaCode').value;
var dom = new DOMParser().parseFromString(rel_attribute, 'text/html');
[...dom.getElementsByTagName('a')].forEach((a) => {
a.setAttribute('rel', 'nofollow');
alert(a.outerHTML);
});
}
<textarea id="textareaCode"></textarea>
<a href="#" onclick="naming()">Execute Function</a>