I am looking for jQuery translation from the following:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
taken from the following site:
http://articles.sitepoint.com/article/standards-compliant-world/3
I started with something similar, but I don’t know how to look for the rel attribute (without scrolling through all the bindings):
$(document).ready(function () {
$('body').find('a').findTheRelTagWithExternalValue;
});
Thanks
Red
source
share