title: Change link target attribute if its href attribute contains certain phrase
body: <p>I am trying to check all anchors' tags using <code>.each()</code> and set home URLs' target to <code>_self</code> and other non-home URLs' target to <code>_blank</code>.</p>
  
  <p>So far, I got this:</p>
  
  <pre><code>$('a').each(function() {
      var homeURL = 'google.ca';    
      if ( $(this+'[href*='+homeURL+']')) {
          $(this).attr('target','_self');
      }else{
          $(this).attr('target','_blank');
      }  
  });
  </code></pre>
  
  <p>This is also on jsBin <a href="http://jsbin.com/inifov" rel="noreferrer">here</a>.</p>
  
  <p>For some reason, the non-home URLs set to <code>target="_self"</code>. Can anyone explain why?</p>