JSFiddle - React, Tailwind, and code Playground
by Shree Khanal
HTML
<p>
<a href="https://bing.com">Bing</a> <span class="ext"></span> and an <a href="https://rev.press">internal link </a> <span class="ext"></span>.
</p>
<p>
<a href="https://google.com">Google</a> <span class="ext"></span> and an <a href="https://rev.press/topic/news/">internal link </a> <span class="ext"></span> .
</p>
CSS
.external {
width: 16px;
height: 16px;
display: inline-block;
vertical-align: bottom;
background-image: url('https://rev.press/wp-content/uploads/2022/11/new-tab.svg');
background-size: contain;
cursor: pointer;
}
JavaScript
var $lnk = $('a:not([href^="https://rev.press"]):not([href^="#"]):not([href^="/"])');
$lnk.next('.ext').addClass('external').append("<a 'target'='_blank' href=" + $lnk.attr('href') + " >")
$(".ext").on("click", function(e) {
var link = $(e.currentTarget).find('a');
alert(link.length);
var win = window.open(link.attr('href'), link.attr('target'));
});