JSFiddle - React, Tailwind, and code Playground

by rodrigonery

HTML

<a id="google" href="http://www.google.com">Google</a><p>

<a id="facebook" href="http://www.facebook.com">Facebook</a><p>

<!-- Normal Link without jQuery-->

<a href="http://www.yahoo.com">Yahoo</a>

CSS

p {
    margin-top: 5%;
}

JavaScript

/*
$(function () {
    $("#google").attr("target", "_blank");
    $("#facebook").attr("target", "_blank");
});
*/

// With .prop();
/*
$(function () {
    $("#google").prop("target", "_blank");
    $("#facebook").prop("target", "_blank");
});
*/

// Awesome? :x

// javaScript pure

function setLink( link ) {
    if (document.getElementsByTagName('a')) {
        for (var i = 0; (link = document.getElementsByTagName('a')[i]); i++) {
            if (link.href.indexOf(yourURL) == -1) {
                link.setAttribute('target', '_blank');
            }
        }
    }
}
setLink('http://www.facebook.com');