Try this instead:
if($(this).is("[href*=" + homeURL + "]")){ $(this).attr('target','_self'); } else { $(this).attr('target','_blank'); }
is() returns true if the selected item matches the selector in the function and false if it is not. So, if the current link href attribute contains google.ca , it will change its target attribute to _self . Otherwise, it will set the value to _blank .
And, in fact, for greater efficiency you should cache $(this) :
var $this = $(this); if($this.is("[href*=" + homeURL + "]")){ $this.attr('target','_self'); } else { $this.attr('target','_blank'); }
source share