Question

I have the following script that adds target="_blank" to all "http" and "https" links:

$(document).ready(function(){
    $("body a[href^='http']").attr("target","_blank");
});

Example: JSFIDDLE

How to add to this script the "ftp" links?

Was it helpful?

Solution

Add the second attribute you want to match against separated by comma:

$(document).ready(function(){
    $("body a[href^='http'],[href^='ftp']").attr("target","_blank");
});

Example: jsFiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top