JSFiddle - React, Tailwind, and code Playground

by 1337

HTML

<button>add</button>
<div>text</div> <a href="//google.com">google</a><div>text</div> <a href="//google.com">google</a><div>text</div> <a href="//google.com">google</a><div>text</div> <a href="//google.com">google</a>

JavaScript

var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  
var observer = new MutationObserver(function(mutations) {  
  $("a").attr('target', '_blank');
});

observer.observe(document, {
    subtree: true,
    attributes: true,
    childList: true,
    characterData: true,
    attributeOldValue: true,
    characterDataOldValue: true
});

$("button").on("click", function() {
    $("a").last().add($("div").last()).clone().insertAfter("a:last");
});