<a href="https://www.sitepoint.com" rel="external">SP</a>
<a href="https://developer.mozilla.org/en-US/">MDN</a>
<a href="https://www.amazon.com" class="amazon">Amazon</a>
a { display: block;}
let links = document.querySelectorAll('a');

document.querySelectorAll('a').forEach(function(link) {
  if (link.getAttribute("rel") == 'external' || link.getAttribute("class") == "amazon") {
    link.target = "_blank";
  }  
})
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.