JSFiddle - React, Tailwind, and code Playground

by Shree Khanal

HTML

<p>
  <a href="https://test.com">internal link</a> <span class="ext"></span> and some test text afterwards.
</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');
  margin-left: 6px;
  background-size: contain;
	cursor: pointer;
}

JavaScript

var $lnk = $('a:not([href^="https://rev.press"]):not([href^="#"]):not([href^="/"])');
//alert($lnk.attr('href'))

//$lnk.attr("target", "_blank").next('span').addClass('external');
$lnk.next('.ext').addClass('external').append("<a 'target'='_blank'  href=" + $lnk.attr('href') + " >")
$(".ext").on("click", function(e) {
  var link = $(e.currentTarget).find('a')
  var win = window.open(link.attr('href'), link.attr('target'));
});